Merge branch 'master' into alund/shared

This commit is contained in:
Stefan Ålund
2020-02-04 10:37:07 +01:00
19 changed files with 1047 additions and 19 deletions
+2
View File
@@ -21,4 +21,6 @@ module.exports = {
version: 'detect',
},
},
// Adding this to .eslintignore just doesn't even, let me know if you can make it work ._.
ignorePatterns: ['**/*_pb.js', '**/*_pb.d.ts'],
};
+2
View File
@@ -23,4 +23,6 @@ module.exports = {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
// Adding this to .eslintignore just doesn't even, let me know if you can make it work ._.
ignorePatterns: ['**/*_pb.js', '**/*_pb.d.ts'],
};
+4 -4
View File
@@ -23,10 +23,10 @@
]
},
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts build",
"test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test",
"lint": "eslint ./src/**/*.{ts,tsx} --max-warnings=0 --format=codeframe"
"start": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts build",
"test": "cross-env EXTEND_ESLINT=true SKIP_PREFLIGHT_CHECK=true react-scripts test",
"lint": "cross-env EXTEND_ESLINT=true eslint ./src/**/*.{ts,tsx} --max-warnings=0 --format=codeframe"
},
"eslintConfig": {
"extends": "react-app"
+3 -2
View File
@@ -5,7 +5,8 @@ import App from './App';
describe('App', () => {
it('renders learn react link', () => {
const rendered = render(<App />);
rendered.getByText('This is Backstage with plugin hello-world');
rendered.getByText('Hello!');
rendered.getByText('This is Backstage!');
rendered.getByText('Backstage is an open platform for building developer portals');
rendered.getByText('…with plugin hello-world:');
});
});
@@ -5,6 +5,8 @@
"main:src": "src/index.ts",
"devDependencies": {
"@backstage/core": "0.0.0",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@spotify/web-scripts": "^6.0.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
@@ -13,14 +15,15 @@
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"google-protobuf": "^3.11.2",
"grpc-web": "^1.0.7",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1"
"react-dom": "^16.12.0"
},
"scripts": {
"lint": "web-scripts lint",
"test": "web-scripts test"
"test": "web-scripts test",
"proto": "../../../scripts/gen-proto.sh hello.proto"
},
"license": "Apache-2.0"
}
@@ -1,15 +1,43 @@
import React, { FC } from 'react';
import React, { FC, useState, useEffect } from 'react';
import Button from '@material-ui/core/Button';
import { HelloPromiseClient } from '../../proto/hello_grpc_web_pb';
import { HelloRequest } from '../../proto/hello_pb';
import { Paper, Typography } from '@material-ui/core';
const MyComponent: FC<{}> = () => {
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>();
useEffect(() => {
const client = new HelloPromiseClient('http://localhost:8080');
const request = new HelloRequest();
request.setName('Spotify');
client.hello(request).then(
reply => {
setMessage(reply.getMessage() ?? '');
},
err => {
setError(err.message);
},
);
}, []);
return (
<Button
variant="contained"
color="primary"
onClick={() => window.location.reload()}
>
Hello!
</Button>
<Paper square>
<Typography variant="body1">{message}</Typography>
<Typography variant="body1" color="error">
{error}
</Typography>
<Button
variant="contained"
color="primary"
onClick={() => window.location.reload()}
>
Hello!
</Button>
</Paper>
);
};
@@ -0,0 +1,32 @@
import * as grpcWeb from 'grpc-web';
import {
HelloReply,
HelloRequest} from './hello_pb';
export class HelloClient {
constructor (hostname: string,
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: string; });
hello(
request: HelloRequest,
metadata: grpcWeb.Metadata | undefined,
callback: (err: grpcWeb.Error,
response: HelloReply) => void
): grpcWeb.ClientReadableStream<HelloReply>;
}
export class HelloPromiseClient {
constructor (hostname: string,
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: string; });
hello(
request: HelloRequest,
metadata?: grpcWeb.Metadata
): Promise<HelloReply>;
}
@@ -0,0 +1,153 @@
/**
* @fileoverview gRPC-Web generated client stub for spotify.backstage.hello.v1alpha1
* @enhanceable
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
const grpc = {};
grpc.web = require('grpc-web');
const proto = {};
proto.spotify = {};
proto.spotify.backstage = {};
proto.spotify.backstage.hello = {};
proto.spotify.backstage.hello.v1alpha1 = require('./hello_pb.js');
/**
* @param {string} hostname
* @param {?Object} credentials
* @param {?Object} options
* @constructor
* @struct
* @final
*/
proto.spotify.backstage.hello.v1alpha1.HelloClient =
function(hostname, credentials, options) {
if (!options) options = {};
options['format'] = 'text';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
*/
this.client_ = new grpc.web.GrpcWebClientBase(options);
/**
* @private @const {string} The hostname
*/
this.hostname_ = hostname;
};
/**
* @param {string} hostname
* @param {?Object} credentials
* @param {?Object} options
* @constructor
* @struct
* @final
*/
proto.spotify.backstage.hello.v1alpha1.HelloPromiseClient =
function(hostname, credentials, options) {
if (!options) options = {};
options['format'] = 'text';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
*/
this.client_ = new grpc.web.GrpcWebClientBase(options);
/**
* @private @const {string} The hostname
*/
this.hostname_ = hostname;
};
/**
* @const
* @type {!grpc.web.MethodDescriptor<
* !proto.spotify.backstage.hello.v1alpha1.HelloRequest,
* !proto.spotify.backstage.hello.v1alpha1.HelloReply>}
*/
const methodDescriptor_Hello_Hello = new grpc.web.MethodDescriptor(
'/spotify.backstage.hello.v1alpha1.Hello/Hello',
grpc.web.MethodType.UNARY,
proto.spotify.backstage.hello.v1alpha1.HelloRequest,
proto.spotify.backstage.hello.v1alpha1.HelloReply,
/**
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} request
* @return {!Uint8Array}
*/
function(request) {
return request.serializeBinary();
},
proto.spotify.backstage.hello.v1alpha1.HelloReply.deserializeBinary
);
/**
* @const
* @type {!grpc.web.AbstractClientBase.MethodInfo<
* !proto.spotify.backstage.hello.v1alpha1.HelloRequest,
* !proto.spotify.backstage.hello.v1alpha1.HelloReply>}
*/
const methodInfo_Hello_Hello = new grpc.web.AbstractClientBase.MethodInfo(
proto.spotify.backstage.hello.v1alpha1.HelloReply,
/**
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} request
* @return {!Uint8Array}
*/
function(request) {
return request.serializeBinary();
},
proto.spotify.backstage.hello.v1alpha1.HelloReply.deserializeBinary
);
/**
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} request The
* request proto
* @param {?Object<string, string>} metadata User defined
* call metadata
* @param {function(?grpc.web.Error, ?proto.spotify.backstage.hello.v1alpha1.HelloReply)}
* callback The callback function(error, response)
* @return {!grpc.web.ClientReadableStream<!proto.spotify.backstage.hello.v1alpha1.HelloReply>|undefined}
* The XHR Node Readable Stream
*/
proto.spotify.backstage.hello.v1alpha1.HelloClient.prototype.hello =
function(request, metadata, callback) {
return this.client_.rpcCall(this.hostname_ +
'/spotify.backstage.hello.v1alpha1.Hello/Hello',
request,
metadata || {},
methodDescriptor_Hello_Hello,
callback);
};
/**
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} request The
* request proto
* @param {?Object<string, string>} metadata User defined
* call metadata
* @return {!Promise<!proto.spotify.backstage.hello.v1alpha1.HelloReply>}
* A native promise that resolves to the response
*/
proto.spotify.backstage.hello.v1alpha1.HelloPromiseClient.prototype.hello =
function(request, metadata) {
return this.client_.unaryCall(this.hostname_ +
'/spotify.backstage.hello.v1alpha1.Hello/Hello',
request,
metadata || {},
methodDescriptor_Hello_Hello);
};
module.exports = proto.spotify.backstage.hello.v1alpha1;
@@ -0,0 +1,38 @@
import * as jspb from "google-protobuf"
export class HelloRequest extends jspb.Message {
getName(): string;
setName(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): HelloRequest.AsObject;
static toObject(includeInstance: boolean, msg: HelloRequest): HelloRequest.AsObject;
static serializeBinaryToWriter(message: HelloRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): HelloRequest;
static deserializeBinaryFromReader(message: HelloRequest, reader: jspb.BinaryReader): HelloRequest;
}
export namespace HelloRequest {
export type AsObject = {
name: string,
}
}
export class HelloReply extends jspb.Message {
getMessage(): string;
setMessage(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): HelloReply.AsObject;
static toObject(includeInstance: boolean, msg: HelloReply): HelloReply.AsObject;
static serializeBinaryToWriter(message: HelloReply, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): HelloReply;
static deserializeBinaryFromReader(message: HelloReply, reader: jspb.BinaryReader): HelloReply;
}
export namespace HelloReply {
export type AsObject = {
message: string,
}
}
@@ -0,0 +1,308 @@
/**
* @fileoverview
* @enhanceable
* @suppress {messageConventions} JS Compiler reports an error if a variable or
* field starts with 'MSG_' and isn't a translatable message.
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();
goog.exportSymbol('proto.spotify.backstage.hello.v1alpha1.HelloReply', null, global);
goog.exportSymbol('proto.spotify.backstage.hello.v1alpha1.HelloRequest', null, global);
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.spotify.backstage.hello.v1alpha1.HelloRequest, jspb.Message);
if (goog.DEBUG && !COMPILED) {
/**
* @public
* @override
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.displayName = 'proto.spotify.backstage.hello.v1alpha1.HelloRequest';
}
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.spotify.backstage.hello.v1alpha1.HelloReply, jspb.Message);
if (goog.DEBUG && !COMPILED) {
/**
* @public
* @override
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.displayName = 'proto.spotify.backstage.hello.v1alpha1.HelloReply';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.prototype.toObject = function(opt_includeInstance) {
return proto.spotify.backstage.hello.v1alpha1.HelloRequest.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, "")
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.spotify.backstage.hello.v1alpha1.HelloRequest}
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.spotify.backstage.hello.v1alpha1.HelloRequest;
return proto.spotify.backstage.hello.v1alpha1.HelloRequest.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.spotify.backstage.hello.v1alpha1.HelloRequest}
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setName(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.spotify.backstage.hello.v1alpha1.HelloRequest.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloRequest} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getName();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
};
/**
* optional string name = 1;
* @return {string}
*/
proto.spotify.backstage.hello.v1alpha1.HelloRequest.prototype.getName = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/** @param {string} value */
proto.spotify.backstage.hello.v1alpha1.HelloRequest.prototype.setName = function(value) {
jspb.Message.setProto3StringField(this, 1, value);
};
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.prototype.toObject = function(opt_includeInstance) {
return proto.spotify.backstage.hello.v1alpha1.HelloReply.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloReply} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.toObject = function(includeInstance, msg) {
var f, obj = {
message: jspb.Message.getFieldWithDefault(msg, 1, "")
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.spotify.backstage.hello.v1alpha1.HelloReply}
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.spotify.backstage.hello.v1alpha1.HelloReply;
return proto.spotify.backstage.hello.v1alpha1.HelloReply.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloReply} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.spotify.backstage.hello.v1alpha1.HelloReply}
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setMessage(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.spotify.backstage.hello.v1alpha1.HelloReply.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.spotify.backstage.hello.v1alpha1.HelloReply} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getMessage();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
};
/**
* optional string message = 1;
* @return {string}
*/
proto.spotify.backstage.hello.v1alpha1.HelloReply.prototype.getMessage = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/** @param {string} value */
proto.spotify.backstage.hello.v1alpha1.HelloReply.prototype.setMessage = function(value) {
jspb.Message.setProto3StringField(this, 1, value);
};
goog.object.extend(exports, proto.spotify.backstage.hello.v1alpha1);
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
OUT='src/proto'
mkdir -p "$OUT"
exec protoc -I="$DIR/../../protos" --js_out=import_style=commonjs:"$OUT" --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:"$OUT" "$@"
+10
View File
@@ -7467,6 +7467,11 @@ globby@^9.2.0:
pify "^4.0.1"
slash "^2.0.0"
google-protobuf@^3.11.2:
version "3.11.2"
resolved "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.11.2.tgz#43272974521a5cec35a21f62730cf517a5a8e38c"
integrity sha512-T4fin7lcYLUPj2ChUZ4DvfuuHtg3xi1621qeRZt2J7SvOQusOzq+sDT4vbotWTCjUXJoR36CA016LlhtPy80uQ==
got@^6.7.1:
version "6.7.1"
resolved "https://registry.npmjs.org/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0"
@@ -7494,6 +7499,11 @@ growly@^1.3.0:
resolved "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
grpc-web@^1.0.7:
version "1.0.7"
resolved "https://registry.npmjs.org/grpc-web/-/grpc-web-1.0.7.tgz#9e4fbcf63d3734515332ab59e42baa7d0d290015"
integrity sha512-Fkbz1nyvvt6GC6ODcxh9Fen6LLB3OTCgGHzHwM2Eni44SUhzqPz1UQgFp9sfBEfInOhx3yBdwo9ZLjZAmJ+TtA==
gzip-size@5.1.1:
version "5.1.1"
resolved "https://registry.npmjs.org/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"