Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STAFFINO-416: Babel: Transpile ES6 server code to client code with RP… #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,062 changes: 271 additions & 791 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
"tslint": "^5.20.1",
"tslint-config-airbnb": "^5.11.2",
"typescript": "^3.7.2"
},
"dependencies": {
"connected-client": "file:packages/connected-client"
}
}
9 changes: 9 additions & 0 deletions packages/connected-babel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `@connected/babel`

> TODO: description

## Usage

```
// TODO: DEMONSTRATE API
```
3 changes: 3 additions & 0 deletions packages/connected-babel/files/async-function.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function asyncFunction(a, b, c) {
return 1;
}
9 changes: 9 additions & 0 deletions packages/connected-babel/files/async-function.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Client from "@connected/client";
export function asyncFunction(...args) {
return Client.execute("asyncFunction", args);
}
Object.defineProperty(asyncFunction, "meta", {
value: {
name: "asyncFunction"
}
});
9 changes: 9 additions & 0 deletions packages/connected-babel/files/default-class.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default class Named {
f1() {
return 1;
}

async f2() {
return 2;
}
}
27 changes: 27 additions & 0 deletions packages/connected-babel/files/default-class.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Client from "@connected/client";
import autoBind from "@connected/auto-bind";
export default class Named {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

f1(...args) {
return Client.execute("Named.f1", args, this ? this.constructorParameters : undefined);
}

f2(...args) {
return Client.execute("Named.f2", args, this ? this.constructorParameters : undefined);
}

}
Object.defineProperty(Named.prototype.f1, "meta", {
value: {
name: "Named.f1"
}
});
Object.defineProperty(Named.prototype.f2, "meta", {
value: {
name: "Named.f2"
}
});
3 changes: 3 additions & 0 deletions packages/connected-babel/files/default-function.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function defaultFunction(a, b, c) {
return 1;
}
9 changes: 9 additions & 0 deletions packages/connected-babel/files/default-function.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Client from "@connected/client";
export default function defaultFunction(...args) {
return Client.execute("defaultFunction", args);
}
Object.defineProperty(defaultFunction, "meta", {
value: {
name: "defaultFunction"
}
});
2 changes: 2 additions & 0 deletions packages/connected-babel/files/imports.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as fs from 'fs';
import * as events from 'events';
1 change: 1 addition & 0 deletions packages/connected-babel/files/imports.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Client from "@connected/client";
9 changes: 9 additions & 0 deletions packages/connected-babel/files/named-class.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Named {
f1() {
return 1;
}

async f2() {
return 2;
}
}
27 changes: 27 additions & 0 deletions packages/connected-babel/files/named-class.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Client from "@connected/client";
import autoBind from "@connected/auto-bind";
export class Named {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

f1(...args) {
return Client.execute("Named.f1", args, this ? this.constructorParameters : undefined);
}

f2(...args) {
return Client.execute("Named.f2", args, this ? this.constructorParameters : undefined);
}

}
Object.defineProperty(Named.prototype.f1, "meta", {
value: {
name: "Named.f1"
}
});
Object.defineProperty(Named.prototype.f2, "meta", {
value: {
name: "Named.f2"
}
});
3 changes: 3 additions & 0 deletions packages/connected-babel/files/named-function.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function namedFunction(a, b, c) {
return 1;
}
9 changes: 9 additions & 0 deletions packages/connected-babel/files/named-function.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Client from "@connected/client";
export function namedFunction(...args) {
return Client.execute("namedFunction", args);
}
Object.defineProperty(namedFunction, "meta", {
value: {
name: "namedFunction"
}
});
6 changes: 6 additions & 0 deletions packages/connected-babel/files/nested-function.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function hostFunction(a, b, c) {
function nestedFunction(x) {
return x;
}
return nestedFunction('abc');
}
9 changes: 9 additions & 0 deletions packages/connected-babel/files/nested-function.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Client from "@connected/client";
export function hostFunction(...args) {
return Client.execute("hostFunction", args);
}
Object.defineProperty(hostFunction, "meta", {
value: {
name: "hostFunction"
}
});
3 changes: 3 additions & 0 deletions packages/connected-babel/files/non-exported-function.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function nonExported(a, b, c) {
return 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Client from "@connected/client";
6 changes: 6 additions & 0 deletions packages/connected-babel/files/statements.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as events from 'events';

const emitter = new events.EventEmitter();
emitter.on('error', (...args) => {
console.log('Error', ...args);
});
1 change: 1 addition & 0 deletions packages/connected-babel/files/statements.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Client from "@connected/client";
5 changes: 5 additions & 0 deletions packages/connected-babel/files/static-method.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class StaticMethod {
static f1() {
return 1;
}
}
9 changes: 9 additions & 0 deletions packages/connected-babel/files/static-method.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Client from "@connected/client";
import autoBind from "@connected/auto-bind";
export class StaticMethod {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

}
45 changes: 45 additions & 0 deletions packages/connected-babel/files/sync-class.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as fs from 'fs';
import * as ts from 'typescript';

const redisClient = ['process.env.REDIS_CLIENT_URL'];

// comment like this - transpile or not to transpile? that's a question!

export class ExportedClass {
constructor(a) {
this.someVariable = a;
}

async classAsyncNamedMethod(a, b, c) {
this.classNamedMethod(5);
return await new Promise((resolve => this.someVariable));
}

classNamedMethod(d) {
console.log('something');
redisClient.push('lala');
}

static classStaticNamedMethod(d) {
console.log('something');
redisClient.push('lala');
}
}

export default class ExportedDefaultClass {
doAnything() {
this.a = '.......';
console.log(this.a);
}
}

class NotExportedClass {
doSomething() {
this.c = '.......';
console.log(this.c);
}
}

export function namedFunction(a, b, c) {
return 5;
}
51 changes: 51 additions & 0 deletions packages/connected-babel/files/sync-class.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Client from "@connected/client";
import autoBind from "@connected/auto-bind";
export class ExportedClass {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

classAsyncNamedMethod(...args) {
return Client.execute("ExportedClass.classAsyncNamedMethod", args, this ? this.constructorParameters : undefined);
}

classNamedMethod(...args) {
return Client.execute("ExportedClass.classNamedMethod", args, this ? this.constructorParameters : undefined);
}

}
Object.defineProperty(ExportedClass.prototype.classAsyncNamedMethod, "meta", {
value: {
name: "ExportedClass.classAsyncNamedMethod"
}
});
Object.defineProperty(ExportedClass.prototype.classNamedMethod, "meta", {
value: {
name: "ExportedClass.classNamedMethod"
}
});
export default class ExportedDefaultClass {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

doAnything(...args) {
return Client.execute("ExportedDefaultClass.doAnything", args, this ? this.constructorParameters : undefined);
}

}
Object.defineProperty(ExportedDefaultClass.prototype.doAnything, "meta", {
value: {
name: "ExportedDefaultClass.doAnything"
}
});
export function namedFunction(...args) {
return Client.execute("namedFunction", args);
}
Object.defineProperty(namedFunction, "meta", {
value: {
name: "namedFunction"
}
});
42 changes: 42 additions & 0 deletions packages/connected-babel/files/wild-west.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as events from 'events';

class PrivateEventEmitter extends events.EventEmitter {

constructor() {
super();
this.on('error', this.listen);
}

async listen(...args) {
console.log('Error', ...args);
}
}

const emitter = new PrivateEventEmitter();

export default class EventEmitterProvider {

constructor(prefix = 'DATA') {
}

invokeError(error) {
emitter.emit(`Error[${this.prefix}]`, error);
}

async notifyError(error) {
const response = await fetch({ body: JSON.stringify(error) });
if (response.status >= 200 && response.status < 300) {
emitter.emit('data', response.body);
} else {
emitter.emit('error', this.formatError(response.body.toString()));
}
}

formatError(body) {
return new Error(body);
}
}

export function factory(prefix) {
return new EventEmitterProvider(prefix);
}
44 changes: 44 additions & 0 deletions packages/connected-babel/files/wild-west.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Client from "@connected/client";
import autoBind from "@connected/auto-bind";
export default class EventEmitterProvider {
constructor(...args) {
this.constructorParameters = args;
autoBind(this);
}

invokeError(...args) {
return Client.execute("EventEmitterProvider.invokeError", args, this ? this.constructorParameters : undefined);
}

notifyError(...args) {
return Client.execute("EventEmitterProvider.notifyError", args, this ? this.constructorParameters : undefined);
}

formatError(...args) {
return Client.execute("EventEmitterProvider.formatError", args, this ? this.constructorParameters : undefined);
}

}
Object.defineProperty(EventEmitterProvider.prototype.invokeError, "meta", {
value: {
name: "EventEmitterProvider.invokeError"
}
});
Object.defineProperty(EventEmitterProvider.prototype.notifyError, "meta", {
value: {
name: "EventEmitterProvider.notifyError"
}
});
Object.defineProperty(EventEmitterProvider.prototype.formatError, "meta", {
value: {
name: "EventEmitterProvider.formatError"
}
});
export function factory(...args) {
return Client.execute("factory", args);
}
Object.defineProperty(factory, "meta", {
value: {
name: "factory"
}
});
Loading