forked from mosn/layotto
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
13,824 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ logs/ | |
/cover.out | ||
vendor/ | ||
demo/state/redis/client | ||
sdk/js-sdk/node_modules | ||
sdk/js-sdk/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Layotto Node.js SDK | ||
|
||
The Layotto Node.js SDK to build your application. | ||
|
||
## Usage | ||
|
||
### State | ||
|
||
#### component.yaml | ||
|
||
```yaml | ||
``` | ||
|
||
#### example.ts | ||
|
||
```ts | ||
import { Client, Server } from 'layotto'; | ||
|
||
const client = new Client(); | ||
const res = await client.invoker.invoke(appId, 'hello-world', HttpMethod.GET); | ||
``` | ||
|
||
## Generate gRPC files | ||
|
||
```bash | ||
npm run build:grpc | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "layotto", | ||
"version": "0.0.0", | ||
"description": "Layotto Node.js SDK", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest --runInBand --detectOpenHandles", | ||
"test:unit": "NODE_ENV=test npm run test 'test/unit/.*\\.test\\.ts'", | ||
"lint": "tslint -p tsconfig.json", | ||
"build:grpc": "scripts/build-grpc.sh", | ||
"build": "tsc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mosn/layotto.git" | ||
}, | ||
"keywords": [ | ||
"layotto", | ||
"mosn" | ||
], | ||
"author": "fengmk2", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/mosn/layotto/issues" | ||
}, | ||
"homepage": "https://github.com/mosn/layotto#readme", | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"grpc-tools": "^1.11.2", | ||
"grpc_tools_node_protoc_ts": "^5.3.2", | ||
"jest": "^27.2.5", | ||
"ts-jest": "^27.0.7", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.4.4" | ||
}, | ||
"dependencies": { | ||
"@grpc/grpc-js": "^1.4.1", | ||
"google-protobuf": "^3.19.0-rc.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// package: spec.proto.runtime.v1 | ||
// file: appcallback.proto | ||
|
||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
import * as grpc from "@grpc/grpc-js"; | ||
import * as appcallback_pb from "./appcallback_pb"; | ||
import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; | ||
|
||
interface IAppCallbackService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> { | ||
listTopicSubscriptions: IAppCallbackService_IListTopicSubscriptions; | ||
onTopicEvent: IAppCallbackService_IOnTopicEvent; | ||
} | ||
|
||
interface IAppCallbackService_IListTopicSubscriptions extends grpc.MethodDefinition<google_protobuf_empty_pb.Empty, appcallback_pb.ListTopicSubscriptionsResponse> { | ||
path: "/spec.proto.runtime.v1.AppCallback/ListTopicSubscriptions"; | ||
requestStream: false; | ||
responseStream: false; | ||
requestSerialize: grpc.serialize<google_protobuf_empty_pb.Empty>; | ||
requestDeserialize: grpc.deserialize<google_protobuf_empty_pb.Empty>; | ||
responseSerialize: grpc.serialize<appcallback_pb.ListTopicSubscriptionsResponse>; | ||
responseDeserialize: grpc.deserialize<appcallback_pb.ListTopicSubscriptionsResponse>; | ||
} | ||
interface IAppCallbackService_IOnTopicEvent extends grpc.MethodDefinition<appcallback_pb.TopicEventRequest, appcallback_pb.TopicEventResponse> { | ||
path: "/spec.proto.runtime.v1.AppCallback/OnTopicEvent"; | ||
requestStream: false; | ||
responseStream: false; | ||
requestSerialize: grpc.serialize<appcallback_pb.TopicEventRequest>; | ||
requestDeserialize: grpc.deserialize<appcallback_pb.TopicEventRequest>; | ||
responseSerialize: grpc.serialize<appcallback_pb.TopicEventResponse>; | ||
responseDeserialize: grpc.deserialize<appcallback_pb.TopicEventResponse>; | ||
} | ||
|
||
export const AppCallbackService: IAppCallbackService; | ||
|
||
export interface IAppCallbackServer extends grpc.UntypedServiceImplementation { | ||
listTopicSubscriptions: grpc.handleUnaryCall<google_protobuf_empty_pb.Empty, appcallback_pb.ListTopicSubscriptionsResponse>; | ||
onTopicEvent: grpc.handleUnaryCall<appcallback_pb.TopicEventRequest, appcallback_pb.TopicEventResponse>; | ||
} | ||
|
||
export interface IAppCallbackClient { | ||
listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
onTopicEvent(request: appcallback_pb.TopicEventRequest, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
onTopicEvent(request: appcallback_pb.TopicEventRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
onTopicEvent(request: appcallback_pb.TopicEventRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
} | ||
|
||
export class AppCallbackClient extends grpc.Client implements IAppCallbackClient { | ||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ClientOptions>); | ||
public listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
public listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
public listTopicSubscriptions(request: google_protobuf_empty_pb.Empty, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: appcallback_pb.ListTopicSubscriptionsResponse) => void): grpc.ClientUnaryCall; | ||
public onTopicEvent(request: appcallback_pb.TopicEventRequest, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
public onTopicEvent(request: appcallback_pb.TopicEventRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
public onTopicEvent(request: appcallback_pb.TopicEventRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: appcallback_pb.TopicEventResponse) => void): grpc.ClientUnaryCall; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// GENERATED CODE -- DO NOT EDIT! | ||
|
||
'use strict'; | ||
var grpc = require('@grpc/grpc-js'); | ||
var appcallback_pb = require('./appcallback_pb.js'); | ||
var google_protobuf_empty_pb = require('google-protobuf/google/protobuf/empty_pb.js'); | ||
|
||
function serialize_google_protobuf_Empty(arg) { | ||
if (!(arg instanceof google_protobuf_empty_pb.Empty)) { | ||
throw new Error('Expected argument of type google.protobuf.Empty'); | ||
} | ||
return Buffer.from(arg.serializeBinary()); | ||
} | ||
|
||
function deserialize_google_protobuf_Empty(buffer_arg) { | ||
return google_protobuf_empty_pb.Empty.deserializeBinary(new Uint8Array(buffer_arg)); | ||
} | ||
|
||
function serialize_spec_proto_runtime_v1_ListTopicSubscriptionsResponse(arg) { | ||
if (!(arg instanceof appcallback_pb.ListTopicSubscriptionsResponse)) { | ||
throw new Error('Expected argument of type spec.proto.runtime.v1.ListTopicSubscriptionsResponse'); | ||
} | ||
return Buffer.from(arg.serializeBinary()); | ||
} | ||
|
||
function deserialize_spec_proto_runtime_v1_ListTopicSubscriptionsResponse(buffer_arg) { | ||
return appcallback_pb.ListTopicSubscriptionsResponse.deserializeBinary(new Uint8Array(buffer_arg)); | ||
} | ||
|
||
function serialize_spec_proto_runtime_v1_TopicEventRequest(arg) { | ||
if (!(arg instanceof appcallback_pb.TopicEventRequest)) { | ||
throw new Error('Expected argument of type spec.proto.runtime.v1.TopicEventRequest'); | ||
} | ||
return Buffer.from(arg.serializeBinary()); | ||
} | ||
|
||
function deserialize_spec_proto_runtime_v1_TopicEventRequest(buffer_arg) { | ||
return appcallback_pb.TopicEventRequest.deserializeBinary(new Uint8Array(buffer_arg)); | ||
} | ||
|
||
function serialize_spec_proto_runtime_v1_TopicEventResponse(arg) { | ||
if (!(arg instanceof appcallback_pb.TopicEventResponse)) { | ||
throw new Error('Expected argument of type spec.proto.runtime.v1.TopicEventResponse'); | ||
} | ||
return Buffer.from(arg.serializeBinary()); | ||
} | ||
|
||
function deserialize_spec_proto_runtime_v1_TopicEventResponse(buffer_arg) { | ||
return appcallback_pb.TopicEventResponse.deserializeBinary(new Uint8Array(buffer_arg)); | ||
} | ||
|
||
|
||
// AppCallback V1 allows user application to interact with runtime. | ||
// User application needs to implement AppCallback service if it needs to | ||
// receive message from runtime. | ||
var AppCallbackService = exports.AppCallbackService = { | ||
// Lists all topics subscribed by this app. | ||
listTopicSubscriptions: { | ||
path: '/spec.proto.runtime.v1.AppCallback/ListTopicSubscriptions', | ||
requestStream: false, | ||
responseStream: false, | ||
requestType: google_protobuf_empty_pb.Empty, | ||
responseType: appcallback_pb.ListTopicSubscriptionsResponse, | ||
requestSerialize: serialize_google_protobuf_Empty, | ||
requestDeserialize: deserialize_google_protobuf_Empty, | ||
responseSerialize: serialize_spec_proto_runtime_v1_ListTopicSubscriptionsResponse, | ||
responseDeserialize: deserialize_spec_proto_runtime_v1_ListTopicSubscriptionsResponse, | ||
}, | ||
// Subscribes events from Pubsub | ||
onTopicEvent: { | ||
path: '/spec.proto.runtime.v1.AppCallback/OnTopicEvent', | ||
requestStream: false, | ||
responseStream: false, | ||
requestType: appcallback_pb.TopicEventRequest, | ||
responseType: appcallback_pb.TopicEventResponse, | ||
requestSerialize: serialize_spec_proto_runtime_v1_TopicEventRequest, | ||
requestDeserialize: deserialize_spec_proto_runtime_v1_TopicEventRequest, | ||
responseSerialize: serialize_spec_proto_runtime_v1_TopicEventResponse, | ||
responseDeserialize: deserialize_spec_proto_runtime_v1_TopicEventResponse, | ||
}, | ||
}; | ||
|
||
exports.AppCallbackClient = grpc.makeGenericClientConstructor(AppCallbackService); | ||
// // Invokes service method with InvokeRequest. | ||
// rpc OnInvoke (InvokeRequest) returns (InvokeResponse) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// package: spec.proto.runtime.v1 | ||
// file: appcallback.proto | ||
|
||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
import * as jspb from "google-protobuf"; | ||
import * as google_protobuf_empty_pb from "google-protobuf/google/protobuf/empty_pb"; | ||
|
||
export class TopicEventRequest extends jspb.Message { | ||
getId(): string; | ||
setId(value: string): TopicEventRequest; | ||
getSource(): string; | ||
setSource(value: string): TopicEventRequest; | ||
getType(): string; | ||
setType(value: string): TopicEventRequest; | ||
getSpecVersion(): string; | ||
setSpecVersion(value: string): TopicEventRequest; | ||
getDataContentType(): string; | ||
setDataContentType(value: string): TopicEventRequest; | ||
getData(): Uint8Array | string; | ||
getData_asU8(): Uint8Array; | ||
getData_asB64(): string; | ||
setData(value: Uint8Array | string): TopicEventRequest; | ||
getTopic(): string; | ||
setTopic(value: string): TopicEventRequest; | ||
getPubsubName(): string; | ||
setPubsubName(value: string): TopicEventRequest; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): TopicEventRequest.AsObject; | ||
static toObject(includeInstance: boolean, msg: TopicEventRequest): TopicEventRequest.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: TopicEventRequest, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): TopicEventRequest; | ||
static deserializeBinaryFromReader(message: TopicEventRequest, reader: jspb.BinaryReader): TopicEventRequest; | ||
} | ||
|
||
export namespace TopicEventRequest { | ||
export type AsObject = { | ||
id: string, | ||
source: string, | ||
type: string, | ||
specVersion: string, | ||
dataContentType: string, | ||
data: Uint8Array | string, | ||
topic: string, | ||
pubsubName: string, | ||
} | ||
} | ||
|
||
export class TopicEventResponse extends jspb.Message { | ||
getStatus(): TopicEventResponse.TopicEventResponseStatus; | ||
setStatus(value: TopicEventResponse.TopicEventResponseStatus): TopicEventResponse; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): TopicEventResponse.AsObject; | ||
static toObject(includeInstance: boolean, msg: TopicEventResponse): TopicEventResponse.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: TopicEventResponse, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): TopicEventResponse; | ||
static deserializeBinaryFromReader(message: TopicEventResponse, reader: jspb.BinaryReader): TopicEventResponse; | ||
} | ||
|
||
export namespace TopicEventResponse { | ||
export type AsObject = { | ||
status: TopicEventResponse.TopicEventResponseStatus, | ||
} | ||
|
||
export enum TopicEventResponseStatus { | ||
SUCCESS = 0, | ||
RETRY = 1, | ||
DROP = 2, | ||
} | ||
|
||
} | ||
|
||
export class ListTopicSubscriptionsResponse extends jspb.Message { | ||
clearSubscriptionsList(): void; | ||
getSubscriptionsList(): Array<TopicSubscription>; | ||
setSubscriptionsList(value: Array<TopicSubscription>): ListTopicSubscriptionsResponse; | ||
addSubscriptions(value?: TopicSubscription, index?: number): TopicSubscription; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ListTopicSubscriptionsResponse.AsObject; | ||
static toObject(includeInstance: boolean, msg: ListTopicSubscriptionsResponse): ListTopicSubscriptionsResponse.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ListTopicSubscriptionsResponse, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ListTopicSubscriptionsResponse; | ||
static deserializeBinaryFromReader(message: ListTopicSubscriptionsResponse, reader: jspb.BinaryReader): ListTopicSubscriptionsResponse; | ||
} | ||
|
||
export namespace ListTopicSubscriptionsResponse { | ||
export type AsObject = { | ||
subscriptionsList: Array<TopicSubscription.AsObject>, | ||
} | ||
} | ||
|
||
export class TopicSubscription extends jspb.Message { | ||
getPubsubName(): string; | ||
setPubsubName(value: string): TopicSubscription; | ||
getTopic(): string; | ||
setTopic(value: string): TopicSubscription; | ||
|
||
getMetadataMap(): jspb.Map<string, string>; | ||
clearMetadataMap(): void; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): TopicSubscription.AsObject; | ||
static toObject(includeInstance: boolean, msg: TopicSubscription): TopicSubscription.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: TopicSubscription, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): TopicSubscription; | ||
static deserializeBinaryFromReader(message: TopicSubscription, reader: jspb.BinaryReader): TopicSubscription; | ||
} | ||
|
||
export namespace TopicSubscription { | ||
export type AsObject = { | ||
pubsubName: string, | ||
topic: string, | ||
|
||
metadataMap: Array<[string, string]>, | ||
} | ||
} |
Oops, something went wrong.