Skip to content

Commit

Permalink
add the ability to do server side streaming and added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonlai committed Oct 26, 2020
1 parent bbc170d commit f309a46
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 56 deletions.
6 changes: 6 additions & 0 deletions generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ export type {{.Name}} = {
{{define "services"}}{{range .}}export class {{.Name}} {
{{- range .Methods}}
{{- if .ServerStreaming }}
static {{.Name}}(req: {{tsType .Input}}, entityNotifier?: gap.NotifyStreamEntityArrival<{{tsType .Output}}>): Promise<gap.FetchState<undefined>> {
return gap.gapFetchGRPCStream<{{tsType .Input}}, {{tsType .Output}}>("{{.URL}}", req, entityNotifier)
}
{{- else }}
static {{.Name}}(req: {{tsType .Input}}): Promise<gap.FetchState<{{tsType .Output}}>> {
return gap.gapFetchGRPC<{{tsType .Input}}, {{tsType .Output}}>("{{.URL}}", req)
}
{{- end}}
{{- end}}
}
{{end}}{{end}}
Expand Down
2 changes: 1 addition & 1 deletion registry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *Registry) analyseService(fileData *data.File, packageName string, fileN

methodData := &data.Method{
Name: method.GetName(),
URL: "/" + serviceURLPart + "/" + method.GetName(),
URL: "/api/" + serviceURLPart + "/" + method.GetName(),
Input: &data.MethodArgument{
Type: inputTypeFQName,
IsExternal: isInputTypeExternal,
Expand Down
3 changes: 0 additions & 3 deletions testdata/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
*/

export enum DataSource {

DataCentre = "DataCentre",

Cloud = "Cloud",

}
3 changes: 0 additions & 3 deletions testdata/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
*/

export enum Environment {

Staging = "Staging",

Production = "Production",

}
55 changes: 6 additions & 49 deletions testdata/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This file is a generated Typescript file for GRPC Gateway, DO NOT MODIFY
*/

import * as gap from "gap/admin/lib/useGapFetch"
import * as ComSquareupCashGapEnvironment from "./environment"
import * as ComSquareupCashGapDatasourceDatasource from "./datasource/datasource"
import * as ComSquareupCashGapEnvironment from "./environment"
import * as gap from "gap/admin/lib/useGapFetch"

type Absent<T, K extends keyof T> = { [k in Exclude<keyof T, K>]?: undefined };
type OneOf<T> =
Expand All @@ -16,131 +16,88 @@ type OneOf<T> =
: never);

export enum LogEntryLevel {

DEBUG = "DEBUG",

INFO = "INFO",

WARN = "WARN",

ERROR = "ERROR",

}

export type LogEntryStackTraceException = {

type?: string

message?: string

}

export type LogEntryStackTraceMethod = {

identifier?: string

file?: string

line?: string

}

export type LogEntryStackTrace = {

exception?: LogEntryStackTraceException

lines?: LogEntryStackTraceMethod[]

}


type BaseLogEntry = {

hostname?: string

level?: LogEntryLevel

elapsed?: number

timestamp?: number

env?: ComSquareupCashGapEnvironment.Environment

hasStackTrace?: boolean

message?: string

tags?: string[]

stackTraces?: LogEntryStackTrace[]

}

export type LogEntry = BaseLogEntry
& OneOf<{ application: string,service: string, }>


type BaseLogStream = {

}

export type LogStream = BaseLogStream
& OneOf<{ dataCentre: DataCentreLogEntries,cloud: CloudLogEntries, }>

export type DataCentreLogEntries = {

logs?: LogEntry[]

}

export type CloudLogEntries = {

logs?: LogEntry[]

}


type BaseFetchLogRequest = {

source?: ComSquareupCashGapDatasourceDatasource.DataSource

}

export type FetchLogRequest = BaseFetchLogRequest
& OneOf<{ application: string,service: string, }>

export type FetchLogResponse = {

result?: LogStream

}

export type PushLogRequest = {

entry?: LogEntry

source?: ComSquareupCashGapDatasourceDatasource.DataSource

}

export type PushLogResponse = {

success?: boolean

}

export class LogService {

static FetchLog(req: FetchLogRequest): Promise<gap.FetchState<FetchLogResponse>> {
return gap.gapFetchGRPC<FetchLogRequest, FetchLogResponse>("/com.squareup.cash.gap.LogService/FetchLog", req)
return gap.gapFetchGRPC<FetchLogRequest, FetchLogResponse>("/api/com.squareup.cash.gap.LogService/FetchLog", req)
}

static StreamLog(req: FetchLogRequest): Promise<gap.FetchState<FetchLogResponse>> {
return gap.gapFetchGRPC<FetchLogRequest, FetchLogResponse>("/com.squareup.cash.gap.LogService/StreamLog", req)
static StreamLog(req: FetchLogRequest, entityNotifier?: gap.NotifyStreamEntityArrival<FetchLogResponse>): Promise<gap.FetchState<undefined>> {
return gap.gapFetchGRPCStream<FetchLogRequest, FetchLogResponse>("/api/com.squareup.cash.gap.LogService/StreamLog", req, entityNotifier)
}

static PushLog(req: PushLogRequest): Promise<gap.FetchState<PushLogResponse>> {
return gap.gapFetchGRPC<PushLogRequest, PushLogResponse>("/com.squareup.cash.gap.LogService/PushLog", req)
return gap.gapFetchGRPC<PushLogRequest, PushLogResponse>("/api/com.squareup.cash.gap.LogService/PushLog", req)
}

}

0 comments on commit f309a46

Please sign in to comment.