From 2e28c4eea8641129ca5e7c2cf90581ec9d0c33c8 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Wed, 2 Aug 2017 13:39:04 -0700 Subject: [PATCH 1/5] chore: initial commit --- .gitignore | 7 +++++ gulpfile.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 22 +++++++++++++ tsconfig.json | 23 ++++++++++++++ tslint.json | 31 +++++++++++++++++++ 5 files changed, 169 insertions(+) create mode 100644 .gitignore create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..caa17e016 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +.vscode +build/ +node_modules/ +npm-debug.log +yarn-error.log +yarn.lock diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..a64e23167 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,86 @@ +const gulp = require('gulp'); +const merge2 = require('merge2'); +const path = require('path'); +const sourcemaps = require('gulp-sourcemaps'); +const tslint = require('gulp-tslint'); +const typescript = require('gulp-typescript'); + +const tslintPath = './tslint.json' +const tsconfigPath = './tsconfig.json'; +const outDir = 'build'; +const srcGlob = 'src/**/*.ts'; + +function onError() {} + +function makeCompileFn(dev) { + const tsSettings = dev ? { + noEmitOnError: false, + noUnusedParameters: false + } : {}; + return () => { + const { dts, js } = gulp.src(srcGlob) + .pipe(sourcemaps.init()) + .pipe(typescript.createProject(tsconfigPath, tsSettings)()) + .on('error', onError); + const jsMap = js.pipe(sourcemaps.write('.', { + includeContent: false, + sourceRoot: path.relative(outDir, 'src') + })); + return merge2([ + js.pipe(gulp.dest(`${outDir}/src`)), + dts.pipe(gulp.dest(`${outDir}/types`)), + jsMap.pipe(gulp.dest(`${outDir}/src`)) + ]); + }; +} + +/** + * Runs tslint on files in src/, with linting rules defined in tslint.json. + */ +gulp.task('lint', () => { + const program = require('tslint').Linter.createProgram(tsconfigPath); + gulp.src(srcGlob) + .pipe(tslint({ + configuration: tslintPath, + formatter: 'prose', + program + })) + .pipe(tslint.report()) + .on('warning', onError); +}); + +/** + * Transpiles TypeScript files in src/ to JavaScript according to the settings + * found in tsconfig.json. + * Currently, all errors are emitted twice. This is being tracked here: + * https://github.com/ivogabe/gulp-typescript/issues/438 + */ +gulp.task('compile', makeCompileFn(false)); + +/** + * Starts watching files in src/, running the 'compile' step whenever a file + * changes. + */ +gulp.task('watch', () => { + gulp.start(['compile']); + return gulp.watch(srcGlob, ['compile']); +}); + +/** + * Transpiles source code with relaxed requirements: + * - Emit output even if there are type-checking errors (this is a workaround + * for the twice-emitted errors in the 'compile' step) + * - Do not emit errors for unused parameters + */ +gulp.task('dev.compile', makeCompileFn(true)); + +/** + * Watches files similar to the 'watch' step, but runs the 'dev.compile' step + * instead. + */ +gulp.task('dev.watch', () => { + gulp.start(['dev.compile']); + return gulp.watch(srcGlob, ['dev.compile']); +}); + +gulp.task('default', ['compile']); diff --git a/package.json b/package.json new file mode 100644 index 000000000..6f0a03068 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "grpc-js", + "version": "0.1.0", + "description": "gRPC client implementation in Node.js", + "main": "index.js", + "engines": { + "node": ">=8.3" + }, + "keywords": [], + "author": "Google Inc.", + "license": "Apache-2.0", + "devDependencies": { + "@types/node": "^8.0.17", + "clang-format": "^1.0.53", + "gulp": "^3.9.1", + "gulp-sourcemaps": "^2.6.0", + "gulp-tslint": "^8.1.1", + "gulp-typescript": "^3.2.1", + "merge2": "^1.1.0", + "typescript": "^2.4.2" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..2032c368c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": false, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "declaration": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es2015"], + "noFallthroughCasesInSwitch": true, + "noEmitOnError": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "pretty": true, + "strict": true, + "module": "commonjs", + "target": "es6", + "sourceMap": true + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/tslint.json b/tslint.json new file mode 100644 index 000000000..fb9deb7e5 --- /dev/null +++ b/tslint.json @@ -0,0 +1,31 @@ +{ + "rules": { + "class-name": true, + "comment-format": [true, "check-space"], + "eofline": true, + "forin": true, + "indent": [true, "spaces"], + "jsdoc-format": true, + "label-position": true, + "no-arg": true, + "no-conditional-assignment": true, + "no-construct": true, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-inferrable-types": true, + "no-internal-module": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "quotemark": [true, "single"], + "radix": true, + "semicolon": [true, "always"], + "switch-default": true, + "triple-equals": [true, "allow-null-check"], + "variable-name": [true, "check-format", "ban-keywords"] + } +} \ No newline at end of file From 554815cbb068e2f06e2f38700df30a05ba4f90ef Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Wed, 2 Aug 2017 13:41:47 -0700 Subject: [PATCH 2/5] feat: add some skeleton classes --- src/call-credentials.ts | 1 + src/call-stream.ts | 14 ++++++++++++++ src/channel-credentials.ts | 20 ++++++++++++++++++++ src/channel.ts | 25 +++++++++++++++++++++++++ src/constants.ts | 19 +++++++++++++++++++ src/metadata.ts | 1 + 6 files changed, 80 insertions(+) create mode 100644 src/call-credentials.ts create mode 100644 src/call-stream.ts create mode 100644 src/channel-credentials.ts create mode 100644 src/channel.ts create mode 100644 src/constants.ts create mode 100644 src/metadata.ts diff --git a/src/call-credentials.ts b/src/call-credentials.ts new file mode 100644 index 000000000..89f782e16 --- /dev/null +++ b/src/call-credentials.ts @@ -0,0 +1 @@ +export class CallCredentials {} diff --git a/src/call-stream.ts b/src/call-stream.ts new file mode 100644 index 000000000..16c5348d5 --- /dev/null +++ b/src/call-stream.ts @@ -0,0 +1,14 @@ +import * as stream from 'stream'; +import { Status } from './constants'; + +/** + * This class represents a duplex stream associated with a single gRPC call. + */ +export class CallStream extends stream.Duplex { + /** + * Cancels the call associated with this stream with a given status. + */ + cancelWithStatus(status: Status) { + throw new Error(); + } +} diff --git a/src/channel-credentials.ts b/src/channel-credentials.ts new file mode 100644 index 000000000..75d72802a --- /dev/null +++ b/src/channel-credentials.ts @@ -0,0 +1,20 @@ +import { CallCredentials } from './call-credentials'; + +/** + * A class that contains credentials for communicating over a channel. + */ +export class ChannelCredentials { + private constructor() {} + + static createSsl(rootCerts: Buffer, privateKey?: Buffer, certChain?: Buffer) : ChannelCredentials { + throw new Error(); + } + + static createInsecure() : ChannelCredentials { + throw new Error(); + } + + compose(callCredentials: CallCredentials) : ChannelCredentials { + throw new Error(); + } +} diff --git a/src/channel.ts b/src/channel.ts new file mode 100644 index 000000000..28c91738f --- /dev/null +++ b/src/channel.ts @@ -0,0 +1,25 @@ +import { CallStream } from './call-stream'; +import { ChannelCredentials } from './channel-credentials'; +import { Metadata } from './metadata'; + +/** + * An interface that contains options used when initializing a Channel instance. + */ +export interface ChannelOptions {} + +/** + * A class that represents a communication channel to a server specified by a given address. + */ +export class Channel { + constructor(address: string, credentials?: ChannelCredentials, options?: ChannelOptions) { + throw new Error(); + } + + createStream(methodName: string, metadata: Metadata) : CallStream { + throw new Error(); + } + + close() { + throw new Error(); + } +} diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 000000000..a72f3388d --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,19 @@ +export enum Status { + OK = 0, + CANCELLED, + UNKNOWN, + INVALID_ARGUMENT, + DEADLINE_EXCEEDED, + NOT_FOUND, + ALREADY_EXISTS, + PERMISSION_DENIED, + RESOURCE_EXHAUSTED, + FAILED_PRECONDITION, + ABORTED, + OUT_OF_RANGE, + UNIMPLEMENTED, + INTERNAL, + UNAVAILABLE, + DATA_LOSS, + UNAUTHENTICATED +} diff --git a/src/metadata.ts b/src/metadata.ts new file mode 100644 index 000000000..2845639cf --- /dev/null +++ b/src/metadata.ts @@ -0,0 +1 @@ +export class Metadata {} From 89245bcd1e6a695df609ce3ca039a50f7afb31f2 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Wed, 2 Aug 2017 15:14:08 -0700 Subject: [PATCH 3/5] Delete tsconfig.json --- tsconfig.json | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 2032c368c..000000000 --- a/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "allowSyntheticDefaultImports": false, - "allowUnreachableCode": false, - "allowUnusedLabels": false, - "declaration": true, - "forceConsistentCasingInFileNames": true, - "lib": ["es2015"], - "noFallthroughCasesInSwitch": true, - "noEmitOnError": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "pretty": true, - "strict": true, - "module": "commonjs", - "target": "es6", - "sourceMap": true - }, - "exclude": [ - "node_modules" - ] -} \ No newline at end of file From 71e5aa6b89ae3029bb5f206931aa81f2d841be5e Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Wed, 2 Aug 2017 15:14:22 -0700 Subject: [PATCH 4/5] Delete tslint.json --- tslint.json | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 tslint.json diff --git a/tslint.json b/tslint.json deleted file mode 100644 index fb9deb7e5..000000000 --- a/tslint.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "rules": { - "class-name": true, - "comment-format": [true, "check-space"], - "eofline": true, - "forin": true, - "indent": [true, "spaces"], - "jsdoc-format": true, - "label-position": true, - "no-arg": true, - "no-conditional-assignment": true, - "no-construct": true, - "no-debugger": true, - "no-duplicate-variable": true, - "no-empty": true, - "no-inferrable-types": true, - "no-internal-module": true, - "no-shadowed-variable": true, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": true, - "no-unused-expression": true, - "no-use-before-declare": true, - "no-var-keyword": true, - "quotemark": [true, "single"], - "radix": true, - "semicolon": [true, "always"], - "switch-default": true, - "triple-equals": [true, "allow-null-check"], - "variable-name": [true, "check-format", "ban-keywords"] - } -} \ No newline at end of file From 367e23ed27d687fd4b9dceba8254254bbb6047ee Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Wed, 2 Aug 2017 15:15:47 -0700 Subject: [PATCH 5/5] Update package.json --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f0a03068..aad00844a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,10 @@ { "name": "grpc-js", "version": "0.1.0", - "description": "gRPC client implementation in Node.js", + "description": "gRPC Library for Node - pure JS", + "homepage": "https://grpc.io/", "main": "index.js", + "private": true, "engines": { "node": ">=8.3" },