Skip to content

Initial import #1

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

Merged
merged 5 commits into from
Aug 2, 2017
Merged
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.vscode
build/
node_modules/
npm-debug.log
yarn-error.log
yarn.lock
86 changes: 86 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "grpc-js",
"version": "0.1.0",
"description": "gRPC Library for Node - pure JS",
"homepage": "https://grpc.io/",
"main": "index.js",
"private": true,
"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"
}
}
1 change: 1 addition & 0 deletions src/call-credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CallCredentials {}
14 changes: 14 additions & 0 deletions src/call-stream.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
20 changes: 20 additions & 0 deletions src/channel-credentials.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
25 changes: 25 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
19 changes: 19 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Metadata {}