Skip to content

Commit e33881e

Browse files
authored
Merge pull request #1 from grpc/kjin
Initial import
2 parents 2350a18 + 367e23e commit e33881e

9 files changed

+197
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.vscode
3+
build/
4+
node_modules/
5+
npm-debug.log
6+
yarn-error.log
7+
yarn.lock

gulpfile.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const gulp = require('gulp');
2+
const merge2 = require('merge2');
3+
const path = require('path');
4+
const sourcemaps = require('gulp-sourcemaps');
5+
const tslint = require('gulp-tslint');
6+
const typescript = require('gulp-typescript');
7+
8+
const tslintPath = './tslint.json'
9+
const tsconfigPath = './tsconfig.json';
10+
const outDir = 'build';
11+
const srcGlob = 'src/**/*.ts';
12+
13+
function onError() {}
14+
15+
function makeCompileFn(dev) {
16+
const tsSettings = dev ? {
17+
noEmitOnError: false,
18+
noUnusedParameters: false
19+
} : {};
20+
return () => {
21+
const { dts, js } = gulp.src(srcGlob)
22+
.pipe(sourcemaps.init())
23+
.pipe(typescript.createProject(tsconfigPath, tsSettings)())
24+
.on('error', onError);
25+
const jsMap = js.pipe(sourcemaps.write('.', {
26+
includeContent: false,
27+
sourceRoot: path.relative(outDir, 'src')
28+
}));
29+
return merge2([
30+
js.pipe(gulp.dest(`${outDir}/src`)),
31+
dts.pipe(gulp.dest(`${outDir}/types`)),
32+
jsMap.pipe(gulp.dest(`${outDir}/src`))
33+
]);
34+
};
35+
}
36+
37+
/**
38+
* Runs tslint on files in src/, with linting rules defined in tslint.json.
39+
*/
40+
gulp.task('lint', () => {
41+
const program = require('tslint').Linter.createProgram(tsconfigPath);
42+
gulp.src(srcGlob)
43+
.pipe(tslint({
44+
configuration: tslintPath,
45+
formatter: 'prose',
46+
program
47+
}))
48+
.pipe(tslint.report())
49+
.on('warning', onError);
50+
});
51+
52+
/**
53+
* Transpiles TypeScript files in src/ to JavaScript according to the settings
54+
* found in tsconfig.json.
55+
* Currently, all errors are emitted twice. This is being tracked here:
56+
* https://github.com/ivogabe/gulp-typescript/issues/438
57+
*/
58+
gulp.task('compile', makeCompileFn(false));
59+
60+
/**
61+
* Starts watching files in src/, running the 'compile' step whenever a file
62+
* changes.
63+
*/
64+
gulp.task('watch', () => {
65+
gulp.start(['compile']);
66+
return gulp.watch(srcGlob, ['compile']);
67+
});
68+
69+
/**
70+
* Transpiles source code with relaxed requirements:
71+
* - Emit output even if there are type-checking errors (this is a workaround
72+
* for the twice-emitted errors in the 'compile' step)
73+
* - Do not emit errors for unused parameters
74+
*/
75+
gulp.task('dev.compile', makeCompileFn(true));
76+
77+
/**
78+
* Watches files similar to the 'watch' step, but runs the 'dev.compile' step
79+
* instead.
80+
*/
81+
gulp.task('dev.watch', () => {
82+
gulp.start(['dev.compile']);
83+
return gulp.watch(srcGlob, ['dev.compile']);
84+
});
85+
86+
gulp.task('default', ['compile']);

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "grpc-js",
3+
"version": "0.1.0",
4+
"description": "gRPC Library for Node - pure JS",
5+
"homepage": "https://grpc.io/",
6+
"main": "index.js",
7+
"private": true,
8+
"engines": {
9+
"node": ">=8.3"
10+
},
11+
"keywords": [],
12+
"author": "Google Inc.",
13+
"license": "Apache-2.0",
14+
"devDependencies": {
15+
"@types/node": "^8.0.17",
16+
"clang-format": "^1.0.53",
17+
"gulp": "^3.9.1",
18+
"gulp-sourcemaps": "^2.6.0",
19+
"gulp-tslint": "^8.1.1",
20+
"gulp-typescript": "^3.2.1",
21+
"merge2": "^1.1.0",
22+
"typescript": "^2.4.2"
23+
}
24+
}

src/call-credentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class CallCredentials {}

src/call-stream.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as stream from 'stream';
2+
import { Status } from './constants';
3+
4+
/**
5+
* This class represents a duplex stream associated with a single gRPC call.
6+
*/
7+
export class CallStream extends stream.Duplex {
8+
/**
9+
* Cancels the call associated with this stream with a given status.
10+
*/
11+
cancelWithStatus(status: Status) {
12+
throw new Error();
13+
}
14+
}

src/channel-credentials.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { CallCredentials } from './call-credentials';
2+
3+
/**
4+
* A class that contains credentials for communicating over a channel.
5+
*/
6+
export class ChannelCredentials {
7+
private constructor() {}
8+
9+
static createSsl(rootCerts: Buffer, privateKey?: Buffer, certChain?: Buffer) : ChannelCredentials {
10+
throw new Error();
11+
}
12+
13+
static createInsecure() : ChannelCredentials {
14+
throw new Error();
15+
}
16+
17+
compose(callCredentials: CallCredentials) : ChannelCredentials {
18+
throw new Error();
19+
}
20+
}

src/channel.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CallStream } from './call-stream';
2+
import { ChannelCredentials } from './channel-credentials';
3+
import { Metadata } from './metadata';
4+
5+
/**
6+
* An interface that contains options used when initializing a Channel instance.
7+
*/
8+
export interface ChannelOptions {}
9+
10+
/**
11+
* A class that represents a communication channel to a server specified by a given address.
12+
*/
13+
export class Channel {
14+
constructor(address: string, credentials?: ChannelCredentials, options?: ChannelOptions) {
15+
throw new Error();
16+
}
17+
18+
createStream(methodName: string, metadata: Metadata) : CallStream {
19+
throw new Error();
20+
}
21+
22+
close() {
23+
throw new Error();
24+
}
25+
}

src/constants.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export enum Status {
2+
OK = 0,
3+
CANCELLED,
4+
UNKNOWN,
5+
INVALID_ARGUMENT,
6+
DEADLINE_EXCEEDED,
7+
NOT_FOUND,
8+
ALREADY_EXISTS,
9+
PERMISSION_DENIED,
10+
RESOURCE_EXHAUSTED,
11+
FAILED_PRECONDITION,
12+
ABORTED,
13+
OUT_OF_RANGE,
14+
UNIMPLEMENTED,
15+
INTERNAL,
16+
UNAVAILABLE,
17+
DATA_LOSS,
18+
UNAUTHENTICATED
19+
}

src/metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class Metadata {}

0 commit comments

Comments
 (0)