@ccmaymay/concrete 4.15.0

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,298 @@
1
+ //
2
+ // Autogenerated by Thrift Compiler (0.15.0)
3
+ //
4
+ // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ //
6
+ "use strict";
7
+
8
+ const thrift = require('thrift');
9
+ const Thrift = thrift.Thrift;
10
+ const Int64 = require('node-int64');
11
+
12
+ const context_ttypes = require('./context_types');
13
+ const metadata_ttypes = require('./metadata_types');
14
+ const language_ttypes = require('./language_types');
15
+ const structure_ttypes = require('./structure_types');
16
+ const entities_ttypes = require('./entities_types');
17
+ const situations_ttypes = require('./situations_types');
18
+ const ex_ttypes = require('./ex_types');
19
+ const email_ttypes = require('./email_types');
20
+ const twitter_ttypes = require('./twitter_types');
21
+ const audio_ttypes = require('./audio_types');
22
+ const communication_ttypes = require('./communication_types');
23
+ const services_ttypes = require('./services_types');
24
+
25
+
26
+ const Service = require('./Service');
27
+ const ServiceClient = Service.Client;
28
+ const ServiceProcessor = Service.Processor;
29
+ const ttypes = require('./annotate_types');
30
+ //HELPER FUNCTIONS AND STRUCTURES
31
+
32
+ const AnnotateWithContextService_annotate_args = class {
33
+ constructor(args) {
34
+ this.original = null;
35
+ this.context = null;
36
+ if (args) {
37
+ if (args.original !== undefined && args.original !== null) {
38
+ this.original = new communication_ttypes.Communication(args.original);
39
+ }
40
+ if (args.context !== undefined && args.context !== null) {
41
+ this.context = new context_ttypes.Context(args.context);
42
+ }
43
+ }
44
+ }
45
+
46
+ read (input) {
47
+ input.readStructBegin();
48
+ while (true) {
49
+ const ret = input.readFieldBegin();
50
+ const ftype = ret.ftype;
51
+ const fid = ret.fid;
52
+ if (ftype == Thrift.Type.STOP) {
53
+ break;
54
+ }
55
+ switch (fid) {
56
+ case 1:
57
+ if (ftype == Thrift.Type.STRUCT) {
58
+ this.original = new communication_ttypes.Communication();
59
+ this.original.read(input);
60
+ } else {
61
+ input.skip(ftype);
62
+ }
63
+ break;
64
+ case 2:
65
+ if (ftype == Thrift.Type.STRUCT) {
66
+ this.context = new context_ttypes.Context();
67
+ this.context.read(input);
68
+ } else {
69
+ input.skip(ftype);
70
+ }
71
+ break;
72
+ default:
73
+ input.skip(ftype);
74
+ }
75
+ input.readFieldEnd();
76
+ }
77
+ input.readStructEnd();
78
+ return;
79
+ }
80
+
81
+ write (output) {
82
+ output.writeStructBegin('AnnotateWithContextService_annotate_args');
83
+ if (this.original !== null && this.original !== undefined) {
84
+ output.writeFieldBegin('original', Thrift.Type.STRUCT, 1);
85
+ this.original.write(output);
86
+ output.writeFieldEnd();
87
+ }
88
+ if (this.context !== null && this.context !== undefined) {
89
+ output.writeFieldBegin('context', Thrift.Type.STRUCT, 2);
90
+ this.context.write(output);
91
+ output.writeFieldEnd();
92
+ }
93
+ output.writeFieldStop();
94
+ output.writeStructEnd();
95
+ return;
96
+ }
97
+
98
+ };
99
+ const AnnotateWithContextService_annotate_result = class {
100
+ constructor(args) {
101
+ this.success = null;
102
+ this.ex = null;
103
+ if (args instanceof ex_ttypes.ConcreteThriftException) {
104
+ this.ex = args;
105
+ return;
106
+ }
107
+ if (args) {
108
+ if (args.success !== undefined && args.success !== null) {
109
+ this.success = new communication_ttypes.Communication(args.success);
110
+ }
111
+ if (args.ex !== undefined && args.ex !== null) {
112
+ this.ex = args.ex;
113
+ }
114
+ }
115
+ }
116
+
117
+ read (input) {
118
+ input.readStructBegin();
119
+ while (true) {
120
+ const ret = input.readFieldBegin();
121
+ const ftype = ret.ftype;
122
+ const fid = ret.fid;
123
+ if (ftype == Thrift.Type.STOP) {
124
+ break;
125
+ }
126
+ switch (fid) {
127
+ case 0:
128
+ if (ftype == Thrift.Type.STRUCT) {
129
+ this.success = new communication_ttypes.Communication();
130
+ this.success.read(input);
131
+ } else {
132
+ input.skip(ftype);
133
+ }
134
+ break;
135
+ case 1:
136
+ if (ftype == Thrift.Type.STRUCT) {
137
+ this.ex = new ex_ttypes.ConcreteThriftException();
138
+ this.ex.read(input);
139
+ } else {
140
+ input.skip(ftype);
141
+ }
142
+ break;
143
+ default:
144
+ input.skip(ftype);
145
+ }
146
+ input.readFieldEnd();
147
+ }
148
+ input.readStructEnd();
149
+ return;
150
+ }
151
+
152
+ write (output) {
153
+ output.writeStructBegin('AnnotateWithContextService_annotate_result');
154
+ if (this.success !== null && this.success !== undefined) {
155
+ output.writeFieldBegin('success', Thrift.Type.STRUCT, 0);
156
+ this.success.write(output);
157
+ output.writeFieldEnd();
158
+ }
159
+ if (this.ex !== null && this.ex !== undefined) {
160
+ output.writeFieldBegin('ex', Thrift.Type.STRUCT, 1);
161
+ this.ex.write(output);
162
+ output.writeFieldEnd();
163
+ }
164
+ output.writeFieldStop();
165
+ output.writeStructEnd();
166
+ return;
167
+ }
168
+
169
+ };
170
+ const AnnotateWithContextServiceClient = exports.Client = class AnnotateWithContextServiceClient extends ServiceClient {
171
+ constructor(output, pClass) {
172
+ super(output, pClass);
173
+ this.output = output;
174
+ this.pClass = pClass;
175
+ this._seqid = 0;
176
+ this._reqs = {};
177
+ }
178
+ seqid () { return this._seqid; }
179
+ new_seqid () { return this._seqid += 1; }
180
+
181
+ annotate (original, context) {
182
+ this._seqid = this.new_seqid();
183
+ const self = this;
184
+ return new Promise((resolve, reject) => {
185
+ self._reqs[self.seqid()] = (error, result) => {
186
+ return error ? reject(error) : resolve(result);
187
+ };
188
+ self.send_annotate(original, context);
189
+ });
190
+ }
191
+
192
+ send_annotate (original, context) {
193
+ const output = new this.pClass(this.output);
194
+ const params = {
195
+ original: original,
196
+ context: context
197
+ };
198
+ const args = new AnnotateWithContextService_annotate_args(params);
199
+ try {
200
+ output.writeMessageBegin('annotate', Thrift.MessageType.CALL, this.seqid());
201
+ args.write(output);
202
+ output.writeMessageEnd();
203
+ return this.output.flush();
204
+ }
205
+ catch (e) {
206
+ delete this._reqs[this.seqid()];
207
+ if (typeof output.reset === 'function') {
208
+ output.reset();
209
+ }
210
+ throw e;
211
+ }
212
+ }
213
+
214
+ recv_annotate (input, mtype, rseqid) {
215
+ const callback = this._reqs[rseqid] || function() {};
216
+ delete this._reqs[rseqid];
217
+ if (mtype == Thrift.MessageType.EXCEPTION) {
218
+ const x = new Thrift.TApplicationException();
219
+ x.read(input);
220
+ input.readMessageEnd();
221
+ return callback(x);
222
+ }
223
+ const result = new AnnotateWithContextService_annotate_result();
224
+ result.read(input);
225
+ input.readMessageEnd();
226
+
227
+ if (null !== result.ex) {
228
+ return callback(result.ex);
229
+ }
230
+ if (null !== result.success) {
231
+ return callback(null, result.success);
232
+ }
233
+ return callback('annotate failed: unknown result');
234
+ }
235
+ };
236
+ const AnnotateWithContextServiceProcessor = exports.Processor = class AnnotateWithContextServiceProcessor extends ServiceProcessor {
237
+ constructor(handler) {
238
+ super(handler);
239
+ this._handler = handler;
240
+ }
241
+ process (input, output) {
242
+ const r = input.readMessageBegin();
243
+ if (this['process_' + r.fname]) {
244
+ return this['process_' + r.fname].call(this, r.rseqid, input, output);
245
+ } else {
246
+ input.skip(Thrift.Type.STRUCT);
247
+ input.readMessageEnd();
248
+ const x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname);
249
+ output.writeMessageBegin(r.fname, Thrift.MessageType.EXCEPTION, r.rseqid);
250
+ x.write(output);
251
+ output.writeMessageEnd();
252
+ output.flush();
253
+ }
254
+ }
255
+ process_annotate (seqid, input, output) {
256
+ const args = new AnnotateWithContextService_annotate_args();
257
+ args.read(input);
258
+ input.readMessageEnd();
259
+ if (this._handler.annotate.length === 2) {
260
+ Promise.resolve(this._handler.annotate.bind(this._handler)(
261
+ args.original,
262
+ args.context
263
+ )).then(result => {
264
+ const result_obj = new AnnotateWithContextService_annotate_result({success: result});
265
+ output.writeMessageBegin("annotate", Thrift.MessageType.REPLY, seqid);
266
+ result_obj.write(output);
267
+ output.writeMessageEnd();
268
+ output.flush();
269
+ }).catch(err => {
270
+ let result;
271
+ if (err instanceof ex_ttypes.ConcreteThriftException) {
272
+ result = new AnnotateWithContextService_annotate_result(err);
273
+ output.writeMessageBegin("annotate", Thrift.MessageType.REPLY, seqid);
274
+ } else {
275
+ result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
276
+ output.writeMessageBegin("annotate", Thrift.MessageType.EXCEPTION, seqid);
277
+ }
278
+ result.write(output);
279
+ output.writeMessageEnd();
280
+ output.flush();
281
+ });
282
+ } else {
283
+ this._handler.annotate(args.original, args.context, (err, result) => {
284
+ let result_obj;
285
+ if ((err === null || typeof err === 'undefined') || err instanceof ex_ttypes.ConcreteThriftException) {
286
+ result_obj = new AnnotateWithContextService_annotate_result((err !== null || typeof err === 'undefined') ? err : {success: result});
287
+ output.writeMessageBegin("annotate", Thrift.MessageType.REPLY, seqid);
288
+ } else {
289
+ result_obj = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
290
+ output.writeMessageBegin("annotate", Thrift.MessageType.EXCEPTION, seqid);
291
+ }
292
+ result_obj.write(output);
293
+ output.writeMessageEnd();
294
+ output.flush();
295
+ });
296
+ }
297
+ }
298
+ };