@nsshunt/stsappframework 3.1.27 → 3.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=commonTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonTypes.js","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/commonTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ /*
31
+ *
32
+ * Copyright 2015 gRPC authors.
33
+ *
34
+ * Licensed under the Apache License, Version 2.0 (the "License");
35
+ * you may not use this file except in compliance with the License.
36
+ * You may obtain a copy of the License at
37
+ *
38
+ * http://www.apache.org/licenses/LICENSE-2.0
39
+ *
40
+ * Unless required by applicable law or agreed to in writing, software
41
+ * distributed under the License is distributed on an "AS IS" BASIS,
42
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43
+ * See the License for the specific language governing permissions and
44
+ * limitations under the License.
45
+ *
46
+ */
47
+ const PROTO_PATH_CL = __dirname + './../../../../src/gRPC/ststest/protos/route_guide.proto';
48
+ const grpc = __importStar(require("@grpc/grpc-js"));
49
+ const protoLoader = __importStar(require("@grpc/proto-loader"));
50
+ const chalk_1 = __importDefault(require("chalk"));
51
+ const packageDefinition = protoLoader.loadSync(PROTO_PATH_CL, { keepCase: true,
52
+ longs: String,
53
+ enums: String,
54
+ defaults: true,
55
+ oneofs: true
56
+ });
57
+ const routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
58
+ const client = new routeguide.RouteGuide('localhost:50051', grpc.credentials.createInsecure());
59
+ /**
60
+ * Run the getFeature demo. Calls getFeature with a point known to have a
61
+ * feature and a point known not to have a feature.
62
+ * @param {function} callback Called when this demo is complete
63
+ */
64
+ const runGetFeature = async () => {
65
+ return new Promise((resolve, reject) => {
66
+ console.log(chalk_1.default.grey(`runGetFeature: Starting ...`));
67
+ function featureCallback(error, feature) {
68
+ if (error) {
69
+ reject(error);
70
+ return;
71
+ }
72
+ if (feature.name === '') {
73
+ console.log(chalk_1.default.grey('runGetFeature: Found no feature at ' +
74
+ feature.location.latitude + ', ' +
75
+ feature.location.longitude));
76
+ }
77
+ else {
78
+ console.log(chalk_1.default.grey('runGetFeature: Found feature called "' + feature.name + '" at ' +
79
+ feature.location.latitude + ', ' +
80
+ feature.location.longitude));
81
+ }
82
+ console.log(chalk_1.default.grey(`runGetFeature: End`));
83
+ resolve();
84
+ }
85
+ const point1 = {
86
+ latitude: 1,
87
+ longitude: 2
88
+ };
89
+ client.getFeature(point1, featureCallback);
90
+ });
91
+ };
92
+ /**
93
+ * Run the listFeatures demo. Calls listFeatures with a rectangle containing all
94
+ * of the features in the pre-generated database. Prints each response as it
95
+ * comes in.
96
+ * @param {function} callback Called when this demo is complete
97
+ */
98
+ const runListFeatures = async () => {
99
+ return new Promise((resolve, reject) => {
100
+ console.log(chalk_1.default.green(`runListFeatures: Starting ...`));
101
+ // Setup timeout ...
102
+ const timeout = setTimeout(() => {
103
+ console.log(chalk_1.default.green(`runListFeatures: End in error state - timeout`));
104
+ reject('Timeout error ...');
105
+ }, 10000);
106
+ const rectangle = {
107
+ lo: {
108
+ latitude: 1,
109
+ longitude: 2
110
+ },
111
+ hi: {
112
+ latitude: 3,
113
+ longitude: 4
114
+ }
115
+ };
116
+ console.log(chalk_1.default.green('runListFeatures: Looking for features between 40, -75 and 42, -73'));
117
+ const call = client.listFeatures(rectangle);
118
+ call.on('data', function (feature) {
119
+ console.log(chalk_1.default.green('runListFeatures: Found feature called "' + feature.name + '" at ' +
120
+ feature.location.latitude + ', ' +
121
+ feature.location.longitude));
122
+ });
123
+ call.on('end', () => {
124
+ console.log(chalk_1.default.green(`runListFeatures: End`));
125
+ clearTimeout(timeout);
126
+ resolve();
127
+ });
128
+ });
129
+ };
130
+ /**
131
+ * Run the recordRoute demo. Sends several randomly chosen points from the
132
+ * pre-generated feature database with a variable delay in between. Prints the
133
+ * statistics when they are sent from the server.
134
+ * @param {function} callback Called when this demo is complete
135
+ */
136
+ const runRecordRoute = async () => {
137
+ return new Promise((resolve, reject) => {
138
+ console.log(chalk_1.default.magenta(`runRecordRoute: Starting ...`));
139
+ const call = client.recordRoute(function (error, stats) {
140
+ if (error) {
141
+ console.log(chalk_1.default.magenta(`runRecordRoute: End (in error state): [${error}]`));
142
+ reject(error);
143
+ return;
144
+ }
145
+ console.log('Finished trip with', stats.point_count, 'points');
146
+ console.log('Passed', stats.feature_count, 'features');
147
+ console.log('Travelled', stats.distance, 'meters');
148
+ console.log('It took', stats.elapsed_time, 'seconds');
149
+ console.log(chalk_1.default.magenta(`runRecordRoute: End`));
150
+ resolve();
151
+ });
152
+ // Now stream data to the server
153
+ for (let i = 0; i < 10; i++) {
154
+ console.log(chalk_1.default.magenta(`runRecordRoute: Sending iteration: [${i}]`));
155
+ call.write({
156
+ latitude: i,
157
+ longitude: i * 2
158
+ });
159
+ }
160
+ // now sleep some random delay ...
161
+ console.log(chalk_1.default.magenta(`runRecordRoute: Sending End`));
162
+ call.end();
163
+ });
164
+ };
165
+ /**
166
+ * Run the routeChat demo. Send some chat messages, and print any chat messages
167
+ * that are sent from the server.
168
+ * @param {function} callback Called when the demo is complete
169
+ */
170
+ const runRouteChat = async () => {
171
+ return new Promise((resolve, reject) => {
172
+ console.log(chalk_1.default.cyan(`runRouteChat: Starting ...`));
173
+ // Setup timeout ...
174
+ const timeout = setTimeout(() => {
175
+ console.log(chalk_1.default.cyan(`runRouteChat: End in error state - timeout`));
176
+ reject('Timeout error ...');
177
+ }, 10000);
178
+ const call = client.routeChat();
179
+ // Stream data from the server event
180
+ call.on('data', function (note) {
181
+ console.log(chalk_1.default.cyan('Got message "' + note.message + '" at ' +
182
+ note.location.latitude + ', ' + note.location.longitude));
183
+ });
184
+ // When server completed, end is invoked
185
+ call.on('end', () => {
186
+ clearTimeout(timeout);
187
+ console.log(chalk_1.default.cyan(`runRouteChat: End`));
188
+ resolve();
189
+ });
190
+ // Now stream data to the server
191
+ const notes = [{
192
+ location: {
193
+ latitude: 1,
194
+ longitude: 2
195
+ },
196
+ message: 'First message'
197
+ }, {
198
+ location: {
199
+ latitude: 3,
200
+ longitude: 4
201
+ },
202
+ message: 'Second message'
203
+ }, {
204
+ location: {
205
+ latitude: 5,
206
+ longitude: 6
207
+ },
208
+ message: 'Third message'
209
+ }, {
210
+ location: {
211
+ latitude: 7,
212
+ longitude: 8
213
+ },
214
+ message: 'Fourth message'
215
+ }];
216
+ for (let i = 0; i < notes.length; i++) {
217
+ const note = notes[i];
218
+ console.log(chalk_1.default.cyan('Sending message "' + note.message + '" at ' +
219
+ note.location.latitude + ', ' + note.location.longitude));
220
+ call.write(note);
221
+ }
222
+ console.log(chalk_1.default.cyan(`Calling end`));
223
+ call.end();
224
+ });
225
+ };
226
+ /**
227
+ * Run all of the demos in order
228
+ */
229
+ async function main() {
230
+ const start = performance.now();
231
+ const totalIterations = 5000;
232
+ for (let i = 0; i < totalIterations; i++) {
233
+ const promArray = [];
234
+ promArray.push(runGetFeature());
235
+ promArray.push(runListFeatures());
236
+ promArray.push(runRecordRoute());
237
+ promArray.push(runRouteChat());
238
+ await Promise.all(promArray);
239
+ console.log(i);
240
+ }
241
+ const end = performance.now();
242
+ console.log(`total time = ${end - start}`);
243
+ console.log(`iterations per second = ${(totalIterations / (end - start)) * 1000.0}`);
244
+ }
245
+ if (require.main === module) {
246
+ main();
247
+ }
248
+ exports.runGetFeature = runGetFeature;
249
+ exports.runListFeatures = runListFeatures;
250
+ exports.runRecordRoute = runRecordRoute;
251
+ exports.runRouteChat = runRouteChat;
252
+ //# sourceMappingURL=route_guide_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route_guide_client.js","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/route_guide_client.ts"],"names":[],"mappings":";AAAA,kDAAkD,CAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9D;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,aAAa,GAAG,SAAS,GAAG,yDAAyD,CAAC;AAE5F,oDAAsC;AACtC,gEAAkD;AAIlD,kDAAyB;AAEzB,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAC1C,aAAa,EACb,EAAC,QAAQ,EAAE,IAAI;IACX,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;CACf,CAAC,CAAC;AACP,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,UAAU,CAAC;AAC5E,MAAM,MA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IAC7B,KAAK,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;QAErC,MAAM,SAAS,GAAoB,EAAG,CAAC;QAEvC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAChC,SAAS,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QAClC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QACjC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAE/B,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAE9B,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAC,KAAK,EAAE,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,eAAe,GAAG,CAAC,GAAG,GAAC,KAAK,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC;AAEvF,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC;AACX,CAAC;AAED,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC,OAAO,CAAC,eAAe,GAAG,eAAe,CAAC;AAC1C,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC;AACxC,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ /*
31
+ *
32
+ * Copyright 2015 gRPC authors.
33
+ *
34
+ * Licensed under the Apache License, Version 2.0 (the "License");
35
+ * you may not use this file except in compliance with the License.
36
+ * You may obtain a copy of the License at
37
+ *
38
+ * http://www.apache.org/licenses/LICENSE-2.0
39
+ *
40
+ * Unless required by applicable law or agreed to in writing, software
41
+ * distributed under the License is distributed on an "AS IS" BASIS,
42
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43
+ * See the License for the specific language governing permissions and
44
+ * limitations under the License.
45
+ *
46
+ */
47
+ const PROTO_PATH_SV = __dirname + './../../../../src/gRPC/ststest/protos/route_guide.proto';
48
+ const grpc = __importStar(require("@grpc/grpc-js"));
49
+ const protoLoader = __importStar(require("@grpc/proto-loader"));
50
+ const chalk_1 = __importDefault(require("chalk"));
51
+ const packageDefinition = protoLoader.loadSync(PROTO_PATH_SV, { keepCase: true,
52
+ longs: String,
53
+ enums: String,
54
+ defaults: true,
55
+ oneofs: true
56
+ });
57
+ const routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
58
+ /**
59
+ * Get a feature object at the given point, or creates one if it does not exist.
60
+ * @param {point} point The point to check
61
+ * @return {feature} The feature object at the point. Note that an empty name
62
+ * indicates no feature
63
+ */
64
+ function checkFeature(point) {
65
+ const feature = {
66
+ name: "Some name",
67
+ location: {
68
+ latitude: point.latitude * 2,
69
+ longitude: point.longitude * 2
70
+ }
71
+ };
72
+ return feature;
73
+ }
74
+ /**
75
+ * getFeature request handler. Gets a request with a point, and responds with a
76
+ * feature object indicating whether there is a feature at that point.
77
+ * @param {EventEmitter} call Call object for the handler to process
78
+ * @param {function(Error, feature)} callback Response callback
79
+ */
80
+ function getFeature(call, callback) {
81
+ console.log(chalk_1.default.grey(`getFeature: call.request: [${JSON.stringify(call.request)}]`));
82
+ const retVal = checkFeature(call.request);
83
+ console.log(chalk_1.default.grey(`getFeature: return: [${JSON.stringify(retVal)}]`));
84
+ callback(null, retVal);
85
+ /*
86
+ console.log(chalk.grey(`getFeature2: call.request: [${JSON.stringify(call.request)}]`));
87
+ const retVal: IFeature = checkFeature(call.request as IPoint);
88
+
89
+ console.log(chalk.grey(`getFeature: return value: [${JSON.stringify(retVal)}]`));
90
+ return retVal;
91
+ */
92
+ }
93
+ /**
94
+ * listFeatures request handler. Gets a request with two points, and responds
95
+ * with a stream of all features in the bounding box defined by those points.
96
+ * @param {Writable} call Writable stream for responses with an additional
97
+ * request property for the request value.
98
+ */
99
+ function listFeatures(call) {
100
+ console.log(chalk_1.default.green(`listFeatures: forEach: [${JSON.stringify(call.request)}]`));
101
+ const rectangle = call.request;
102
+ const lo = rectangle.lo;
103
+ const hi = rectangle.hi;
104
+ const feature_list = [];
105
+ for (let i = 0; i < 10; i++) {
106
+ feature_list.push({
107
+ location: {
108
+ latitude: hi.latitude * 2 * (i + 1),
109
+ longitude: lo.longitude * 2 * (i + 1)
110
+ },
111
+ name: `the name for index: [${i}]`
112
+ });
113
+ }
114
+ feature_list.forEach((feature) => {
115
+ console.log(chalk_1.default.green(`listFeatures: forEach: [${JSON.stringify(feature)}]`));
116
+ call.write(feature);
117
+ });
118
+ console.log(chalk_1.default.green(`listFeatures: call.end()`));
119
+ call.end();
120
+ }
121
+ /**
122
+ * recordRoute handler. Gets a stream of points, and responds with statistics
123
+ * about the "trip": number of points, number of known features visited, total
124
+ * distance traveled, and total time spent.
125
+ * @param {Readable} call The request point stream.
126
+ * @param {function(Error, routeSummary)} callback The callback to pass the
127
+ * response to
128
+ */
129
+ function recordRoute(call, callback) {
130
+ let point_count = 0;
131
+ let feature_count = 0;
132
+ let distance = 0;
133
+ let previous = null;
134
+ // Start a timer
135
+ const start_time = process.hrtime();
136
+ call.on('data', function (point) {
137
+ console.log(chalk_1.default.magenta(`recordRoute: on data: [${JSON.stringify(point)}]`));
138
+ point_count += 1;
139
+ if (checkFeature(point).name !== '') {
140
+ feature_count += 1;
141
+ }
142
+ /* For each point after the first, add the incremental distance from the
143
+ * previous point to the total distance value */
144
+ if (previous != null) {
145
+ distance += 1;
146
+ }
147
+ previous = point;
148
+ });
149
+ call.on('end', function () {
150
+ const returnData = {
151
+ point_count: point_count,
152
+ feature_count: feature_count,
153
+ // Cast the distance to an integer
154
+ distance: distance | 0,
155
+ // End the timer
156
+ elapsed_time: process.hrtime(start_time)[0]
157
+ };
158
+ console.log(chalk_1.default.magenta(`recordRoute: on end - return data: [${JSON.stringify(returnData)}]`));
159
+ callback(null, returnData);
160
+ });
161
+ }
162
+ /**
163
+ * routeChat handler. Receives a stream of message/location pairs, and responds
164
+ * with a stream of all previous messages at each of those locations.
165
+ * @param {Duplex} call The stream for incoming and outgoing messages
166
+ */
167
+ function routeChat(call) {
168
+ call.on('data', function (note) {
169
+ console.log(chalk_1.default.cyan(`routeChat: on data: [${JSON.stringify(note)}]`));
170
+ // Send back what we just got
171
+ const sendBack = JSON.parse(JSON.stringify(note));
172
+ sendBack.message = `${note.message} reply message`;
173
+ sendBack.location.latitude = note.location.latitude * 2;
174
+ sendBack.location.longitude = note.location.longitude * 2;
175
+ console.log(chalk_1.default.cyan(`routeChat: sending data: [${JSON.stringify(sendBack)}]`));
176
+ call.write(sendBack);
177
+ });
178
+ call.on('end', function () {
179
+ call.end();
180
+ });
181
+ }
182
+ /**
183
+ * Get a new server with the handler functions in this file bound to the methods
184
+ * it serves.
185
+ * @return {Server} The new server object
186
+ */
187
+ function getServer() {
188
+ const server = new grpc.Server();
189
+ server.addService(routeguide.RouteGuide.service, {
190
+ getFeature: getFeature,
191
+ listFeatures: listFeatures,
192
+ recordRoute: recordRoute,
193
+ routeChat: routeChat
194
+ });
195
+ return server;
196
+ }
197
+ if (require.main === module) {
198
+ // If this is run as a script, start a server on an unused port
199
+ const routeServer = getServer();
200
+ routeServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
201
+ routeServer.start();
202
+ });
203
+ }
204
+ exports.getServer = getServer;
205
+ //# sourceMappingURL=route_guide_server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route_guide_server.js","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/route_guide_server.ts"],"names":[],"mappings":";AAAA,kDAAkD,CAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9D;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,aAAa,GAAG,SAAS,GAAG,yDAAyD,CAAC;AAE5F,oDAAsC;AACtC,gEAAkD;AAIlD,kDAAyB;AAEzB,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAC1C,aAAa,EACb,EAAC,QAAQ,EAAE,IAAI;IACX,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;CACf,CAAC,CAAC;AACP,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,UAAU,CAAC;AAE5E;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa;IAC/B,MAAM,OAAO,GAAa;QACtB,IAAI,EAA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C,CAAC,CAAC;QAClF,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;QACX,IAAI,CAAC,GAAG,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS;IACd,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;IACjC,MAAM,CAAC,UAAU,CAAE,UAAkB,CAAC,UAAU,CAAC,OAAO,EAAE;QACtD,UAAU,EAAE,UAAU;QACtB,YAAY,EAAE,YAAY;QAC1B,WAAW,EAAE,WAAW;QACxB,SAAS,EAAE,SAAS;KACvB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,+DAA+D;IAC/D,MAAM,WAAW,GAAG,SAAS,EAAE,CAAC;IAChC,WAAW,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE;QACjF,WAAW,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsshunt/stsappframework",
3
- "version": "3.1.27",
3
+ "version": "3.1.29",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ clear; node ./dist/gRPC/ststest/src/route_guide_client.js
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ clear; node ./dist/gRPC/ststest/src/route_guide_server.js
@@ -0,0 +1,27 @@
1
+ export interface IPoint {
2
+ latitude: number
3
+ longitude: number;
4
+ }
5
+
6
+ export interface IRectangle {
7
+ lo: IPoint
8
+ hi: IPoint
9
+ }
10
+
11
+ export interface IFeature {
12
+ name: string
13
+ location: IPoint;
14
+ }
15
+
16
+ export interface IRouteNote {
17
+ // The location from which the message is sent.
18
+ location: IPoint
19
+ message: string
20
+ }
21
+
22
+ export interface IRouteSummary {
23
+ point_count: number
24
+ feature_count: number
25
+ distance: number
26
+ elapsed_time: number
27
+ }
@@ -0,0 +1,256 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+
3
+ /*
4
+ *
5
+ * Copyright 2015 gRPC authors.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+
21
+ const PROTO_PATH_CL = __dirname + './../../../../src/gRPC/ststest/protos/route_guide.proto';
22
+
23
+ import * as grpc from '@grpc/grpc-js';
24
+ import * as protoLoader from '@grpc/proto-loader';
25
+
26
+ import { IFeature, IPoint, IRectangle, IRouteNote, IRouteSummary } from './commonTypes'
27
+
28
+ import chalk from 'chalk'
29
+
30
+ const packageDefinition = protoLoader.loadSync(
31
+ PROTO_PATH_CL,
32
+ {keepCase: true,
33
+ longs: String,
34
+ enums: String,
35
+ defaults: true,
36
+ oneofs: true
37
+ });
38
+ const routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
39
+ const client = new (routeguide as any).RouteGuide('localhost:50051',
40
+ grpc.credentials.createInsecure());
41
+
42
+ /**
43
+ * Run the getFeature demo. Calls getFeature with a point known to have a
44
+ * feature and a point known not to have a feature.
45
+ * @param {function} callback Called when this demo is complete
46
+ */
47
+ const runGetFeature = async (): Promise<void> => {
48
+ return new Promise((resolve, reject) => {
49
+ console.log(chalk.grey(`runGetFeature: Starting ...`));
50
+ function featureCallback(error: any, feature: IFeature) {
51
+ if (error) {
52
+ reject(error);
53
+ return;
54
+ }
55
+ if (feature.name === '') {
56
+ console.log(chalk.grey('runGetFeature: Found no feature at ' +
57
+ feature.location.latitude + ', ' +
58
+ feature.location.longitude));
59
+ } else {
60
+ console.log(chalk.grey('runGetFeature: Found feature called "' + feature.name + '" at ' +
61
+ feature.location.latitude + ', ' +
62
+ feature.location.longitude));
63
+ }
64
+ console.log(chalk.grey(`runGetFeature: End`));
65
+ resolve();
66
+ }
67
+ const point1: IPoint = {
68
+ latitude: 1,
69
+ longitude: 2
70
+ };
71
+
72
+ client.getFeature(point1, featureCallback);
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Run the listFeatures demo. Calls listFeatures with a rectangle containing all
78
+ * of the features in the pre-generated database. Prints each response as it
79
+ * comes in.
80
+ * @param {function} callback Called when this demo is complete
81
+ */
82
+ const runListFeatures = async (): Promise<void> => {
83
+ return new Promise((resolve, reject) => {
84
+ console.log(chalk.green(`runListFeatures: Starting ...`));
85
+
86
+ // Setup timeout ...
87
+ const timeout = setTimeout(() => {
88
+ console.log(chalk.green(`runListFeatures: End in error state - timeout`));
89
+ reject('Timeout error ...');
90
+ }, 10000);
91
+
92
+ const rectangle: IRectangle = {
93
+ lo: {
94
+ latitude: 1,
95
+ longitude: 2
96
+ },
97
+ hi: {
98
+ latitude: 3,
99
+ longitude: 4
100
+ }
101
+ };
102
+ console.log(chalk.green('runListFeatures: Looking for features between 40, -75 and 42, -73'));
103
+ const call = client.listFeatures(rectangle);
104
+ call.on('data', function(feature: IFeature) {
105
+ console.log(chalk.green('runListFeatures: Found feature called "' + feature.name + '" at ' +
106
+ feature.location.latitude + ', ' +
107
+ feature.location.longitude));
108
+ });
109
+ call.on('end', () => {
110
+ console.log(chalk.green(`runListFeatures: End`));
111
+ clearTimeout(timeout);
112
+ resolve()
113
+ });
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Run the recordRoute demo. Sends several randomly chosen points from the
119
+ * pre-generated feature database with a variable delay in between. Prints the
120
+ * statistics when they are sent from the server.
121
+ * @param {function} callback Called when this demo is complete
122
+ */
123
+ const runRecordRoute = async (): Promise<void> => {
124
+ return new Promise((resolve, reject) => {
125
+ console.log(chalk.magenta(`runRecordRoute: Starting ...`));
126
+ const call = client.recordRoute(function(error: any, stats: IRouteSummary) {
127
+ if (error) {
128
+ console.log(chalk.magenta(`runRecordRoute: End (in error state): [${error}]`));
129
+ reject(error);
130
+ return;
131
+ }
132
+ console.log('Finished trip with', stats.point_count, 'points');
133
+ console.log('Passed', stats.feature_count, 'features');
134
+ console.log('Travelled', stats.distance, 'meters');
135
+ console.log('It took', stats.elapsed_time, 'seconds');
136
+ console.log(chalk.magenta(`runRecordRoute: End`));
137
+ resolve();
138
+ });
139
+
140
+ // Now stream data to the server
141
+ for (let i = 0; i < 10; i++) {
142
+ console.log(chalk.magenta(`runRecordRoute: Sending iteration: [${i}]`));
143
+ call.write({
144
+ latitude: i,
145
+ longitude: i*2
146
+ } as IPoint);
147
+ }
148
+ // now sleep some random delay ...
149
+ console.log(chalk.magenta(`runRecordRoute: Sending End`));
150
+ call.end();
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Run the routeChat demo. Send some chat messages, and print any chat messages
156
+ * that are sent from the server.
157
+ * @param {function} callback Called when the demo is complete
158
+ */
159
+ const runRouteChat = async (): Promise<void> => {
160
+ return new Promise((resolve, reject) => {
161
+ console.log(chalk.cyan(`runRouteChat: Starting ...`));
162
+
163
+ // Setup timeout ...
164
+ const timeout = setTimeout(() => {
165
+ console.log(chalk.cyan(`runRouteChat: End in error state - timeout`));
166
+ reject('Timeout error ...');
167
+ }, 10000);
168
+
169
+ const call = client.routeChat();
170
+
171
+ // Stream data from the server event
172
+ call.on('data', function(note: IRouteNote) {
173
+ console.log(chalk.cyan('Got message "' + note.message + '" at ' +
174
+ note.location.latitude + ', ' + note.location.longitude));
175
+ });
176
+
177
+ // When server completed, end is invoked
178
+ call.on('end', () => {
179
+ clearTimeout(timeout);
180
+ console.log(chalk.cyan(`runRouteChat: End`));
181
+ resolve();
182
+ });
183
+
184
+ // Now stream data to the server
185
+ const notes = [{
186
+ location: {
187
+ latitude: 1,
188
+ longitude: 2
189
+ },
190
+ message: 'First message'
191
+ }, {
192
+ location: {
193
+ latitude: 3,
194
+ longitude: 4
195
+ },
196
+ message: 'Second message'
197
+ }, {
198
+ location: {
199
+ latitude: 5,
200
+ longitude: 6
201
+ },
202
+ message: 'Third message'
203
+ }, {
204
+ location: {
205
+ latitude: 7,
206
+ longitude: 8
207
+ },
208
+ message: 'Fourth message'
209
+ }];
210
+ for (let i = 0; i < notes.length; i++) {
211
+ const note = notes[i];
212
+ console.log(chalk.cyan('Sending message "' + note.message + '" at ' +
213
+ note.location.latitude + ', ' + note.location.longitude));
214
+ call.write(note);
215
+ }
216
+ console.log(chalk.cyan(`Calling end`));
217
+ call.end();
218
+ });
219
+ }
220
+
221
+ /**
222
+ * Run all of the demos in order
223
+ */
224
+ async function main() {
225
+
226
+ const start = performance.now();
227
+
228
+ const totalIterations = 5000;
229
+ for (let i=0; i < totalIterations; i++) {
230
+
231
+ const promArray: Promise<void>[] = [ ];
232
+
233
+ promArray.push(runGetFeature());
234
+ promArray.push(runListFeatures());
235
+ promArray.push(runRecordRoute());
236
+ promArray.push(runRouteChat());
237
+
238
+ await Promise.all(promArray);
239
+ console.log(i);
240
+ }
241
+
242
+ const end = performance.now();
243
+
244
+ console.log(`total time = ${end-start}`);
245
+ console.log(`iterations per second = ${(totalIterations / (end-start)) * 1000.0}`);
246
+
247
+ }
248
+
249
+ if (require.main === module) {
250
+ main();
251
+ }
252
+
253
+ exports.runGetFeature = runGetFeature;
254
+ exports.runListFeatures = runListFeatures;
255
+ exports.runRecordRoute = runRecordRoute;
256
+ exports.runRouteChat = runRouteChat;
@@ -0,0 +1,194 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
+
3
+ /*
4
+ *
5
+ * Copyright 2015 gRPC authors.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+
21
+ const PROTO_PATH_SV = __dirname + './../../../../src/gRPC/ststest/protos/route_guide.proto';
22
+
23
+ import * as grpc from '@grpc/grpc-js';
24
+ import * as protoLoader from '@grpc/proto-loader';
25
+
26
+ import { IFeature, IPoint, IRectangle, IRouteNote, IRouteSummary } from './commonTypes'
27
+
28
+ import chalk from 'chalk'
29
+
30
+ const packageDefinition = protoLoader.loadSync(
31
+ PROTO_PATH_SV,
32
+ {keepCase: true,
33
+ longs: String,
34
+ enums: String,
35
+ defaults: true,
36
+ oneofs: true
37
+ });
38
+ const routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
39
+
40
+ /**
41
+ * Get a feature object at the given point, or creates one if it does not exist.
42
+ * @param {point} point The point to check
43
+ * @return {feature} The feature object at the point. Note that an empty name
44
+ * indicates no feature
45
+ */
46
+ function checkFeature(point: IPoint): IFeature {
47
+ const feature: IFeature = {
48
+ name: "Some name",
49
+ location: {
50
+ latitude: point.latitude * 2,
51
+ longitude: point.longitude * 2
52
+ }
53
+ };
54
+ return feature;
55
+ }
56
+
57
+ /**
58
+ * getFeature request handler. Gets a request with a point, and responds with a
59
+ * feature object indicating whether there is a feature at that point.
60
+ * @param {EventEmitter} call Call object for the handler to process
61
+ * @param {function(Error, feature)} callback Response callback
62
+ */
63
+ function getFeature(call: any, callback: any) {
64
+ console.log(chalk.grey(`getFeature: call.request: [${JSON.stringify(call.request)}]`));
65
+ const retVal = checkFeature(call.request as IPoint);
66
+ console.log(chalk.grey(`getFeature: return: [${JSON.stringify(retVal)}]`));
67
+ callback(null, retVal);
68
+ /*
69
+ console.log(chalk.grey(`getFeature2: call.request: [${JSON.stringify(call.request)}]`));
70
+ const retVal: IFeature = checkFeature(call.request as IPoint);
71
+
72
+ console.log(chalk.grey(`getFeature: return value: [${JSON.stringify(retVal)}]`));
73
+ return retVal;
74
+ */
75
+ }
76
+
77
+ /**
78
+ * listFeatures request handler. Gets a request with two points, and responds
79
+ * with a stream of all features in the bounding box defined by those points.
80
+ * @param {Writable} call Writable stream for responses with an additional
81
+ * request property for the request value.
82
+ */
83
+ function listFeatures(call: any) {
84
+ console.log(chalk.green(`listFeatures: forEach: [${JSON.stringify(call.request)}]`));
85
+ const rectangle = call.request as IRectangle;
86
+ const lo = rectangle.lo as IPoint;
87
+ const hi = rectangle.hi as IPoint;
88
+
89
+ const feature_list: IFeature[] = [ ];
90
+ for (let i=0; i < 10; i++) {
91
+ feature_list.push({
92
+ location: {
93
+ latitude: hi.latitude * 2 * (i+1),
94
+ longitude: lo.longitude * 2 * (i+1)
95
+ },
96
+ name: `the name for index: [${i}]`
97
+ });
98
+ }
99
+ feature_list.forEach((feature: IFeature) => {
100
+ console.log(chalk.green(`listFeatures: forEach: [${JSON.stringify(feature)}]`));
101
+ call.write(feature);
102
+ });
103
+ console.log(chalk.green(`listFeatures: call.end()`));
104
+ call.end();
105
+ }
106
+
107
+ /**
108
+ * recordRoute handler. Gets a stream of points, and responds with statistics
109
+ * about the "trip": number of points, number of known features visited, total
110
+ * distance traveled, and total time spent.
111
+ * @param {Readable} call The request point stream.
112
+ * @param {function(Error, routeSummary)} callback The callback to pass the
113
+ * response to
114
+ */
115
+ function recordRoute(call: any, callback: any) {
116
+ let point_count = 0;
117
+ let feature_count = 0;
118
+ let distance = 0;
119
+ let previous: any = null;
120
+ // Start a timer
121
+ const start_time = process.hrtime();
122
+ call.on('data', function(point: IPoint) {
123
+ console.log(chalk.magenta(`recordRoute: on data: [${JSON.stringify(point)}]`));
124
+ point_count += 1;
125
+ if (checkFeature(point).name !== '') {
126
+ feature_count += 1;
127
+ }
128
+ /* For each point after the first, add the incremental distance from the
129
+ * previous point to the total distance value */
130
+ if (previous != null) {
131
+ distance += 1;
132
+ }
133
+ previous = point;
134
+ });
135
+ call.on('end', function() {
136
+ const returnData: IRouteSummary = {
137
+ point_count: point_count,
138
+ feature_count: feature_count,
139
+ // Cast the distance to an integer
140
+ distance: distance|0,
141
+ // End the timer
142
+ elapsed_time: process.hrtime(start_time)[0]
143
+ }
144
+ console.log(chalk.magenta(`recordRoute: on end - return data: [${JSON.stringify(returnData)}]`));
145
+ callback(null, returnData);
146
+ });
147
+ }
148
+
149
+ /**
150
+ * routeChat handler. Receives a stream of message/location pairs, and responds
151
+ * with a stream of all previous messages at each of those locations.
152
+ * @param {Duplex} call The stream for incoming and outgoing messages
153
+ */
154
+ function routeChat(call: any) {
155
+ call.on('data', function(note: IRouteNote) {
156
+ console.log(chalk.cyan(`routeChat: on data: [${JSON.stringify(note)}]`));
157
+ // Send back what we just got
158
+ const sendBack: IRouteNote = JSON.parse(JSON.stringify(note));
159
+ sendBack.message = `${note.message} reply message`;
160
+ sendBack.location.latitude = note.location.latitude * 2;
161
+ sendBack.location.longitude = note.location.longitude * 2;
162
+ console.log(chalk.cyan(`routeChat: sending data: [${JSON.stringify(sendBack)}]`));
163
+ call.write(sendBack);
164
+ });
165
+ call.on('end', function() {
166
+ call.end();
167
+ });
168
+ }
169
+
170
+ /**
171
+ * Get a new server with the handler functions in this file bound to the methods
172
+ * it serves.
173
+ * @return {Server} The new server object
174
+ */
175
+ function getServer() {
176
+ const server = new grpc.Server();
177
+ server.addService((routeguide as any).RouteGuide.service, {
178
+ getFeature: getFeature,
179
+ listFeatures: listFeatures,
180
+ recordRoute: recordRoute,
181
+ routeChat: routeChat
182
+ });
183
+ return server;
184
+ }
185
+
186
+ if (require.main === module) {
187
+ // If this is run as a script, start a server on an unused port
188
+ const routeServer = getServer();
189
+ routeServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
190
+ routeServer.start();
191
+ });
192
+ }
193
+
194
+ exports.getServer = getServer;
@@ -0,0 +1,23 @@
1
+ export interface IPoint {
2
+ latitude: number;
3
+ longitude: number;
4
+ }
5
+ export interface IRectangle {
6
+ lo: IPoint;
7
+ hi: IPoint;
8
+ }
9
+ export interface IFeature {
10
+ name: string;
11
+ location: IPoint;
12
+ }
13
+ export interface IRouteNote {
14
+ location: IPoint;
15
+ message: string;
16
+ }
17
+ export interface IRouteSummary {
18
+ point_count: number;
19
+ feature_count: number;
20
+ distance: number;
21
+ elapsed_time: number;
22
+ }
23
+ //# sourceMappingURL=commonTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonTypes.d.ts","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/commonTypes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAEvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;CACvB"}
@@ -0,0 +1,3 @@
1
+
2
+ export {};
3
+ //# sourceMappingURL=route_guide_client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route_guide_client.d.ts","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/route_guide_client.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+
2
+ export {};
3
+ //# sourceMappingURL=route_guide_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route_guide_server.d.ts","sourceRoot":"","sources":["../../../../src/gRPC/ststest/src/route_guide_server.ts"],"names":[],"mappings":""}