@juzi/wechaty-puppet-service 1.0.42 → 1.0.44
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.
- package/dist/cjs/src/client/puppet-service.d.ts +1 -4
- package/dist/cjs/src/client/puppet-service.d.ts.map +1 -1
- package/dist/cjs/src/client/puppet-service.js +47 -129
- package/dist/cjs/src/client/puppet-service.js.map +1 -1
- package/dist/cjs/src/package-json.js +3 -3
- package/dist/cjs/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/cjs/src/server/puppet-implementation.js +14 -66
- package/dist/cjs/src/server/puppet-implementation.js.map +1 -1
- package/dist/esm/src/client/puppet-service.d.ts +1 -4
- package/dist/esm/src/client/puppet-service.d.ts.map +1 -1
- package/dist/esm/src/client/puppet-service.js +44 -126
- package/dist/esm/src/client/puppet-service.js.map +1 -1
- package/dist/esm/src/package-json.js +3 -3
- package/dist/esm/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/esm/src/server/puppet-implementation.js +12 -64
- package/dist/esm/src/server/puppet-implementation.js.map +1 -1
- package/package.json +3 -3
- package/src/client/puppet-service.ts +54 -148
- package/src/package-json.ts +3 -3
- package/src/server/puppet-implementation.ts +16 -82
- package/dist/cjs/src/deprecated/chunk-pb.d.ts +0 -15
- package/dist/cjs/src/deprecated/chunk-pb.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.js +0 -60
- package/dist/cjs/src/deprecated/chunk-pb.js.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.spec.js +0 -144
- package/dist/cjs/src/deprecated/chunk-pb.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts +0 -21
- package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.js +0 -43
- package/dist/cjs/src/deprecated/conversation-id-file-box.js.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js +0 -94
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.d.ts +0 -14
- package/dist/cjs/src/deprecated/file-box-chunk.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.js +0 -67
- package/dist/cjs/src/deprecated/file-box-chunk.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.spec.js +0 -134
- package/dist/cjs/src/deprecated/file-box-chunk.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.d.ts +0 -15
- package/dist/cjs/src/deprecated/file-box-pb.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.js +0 -26
- package/dist/cjs/src/deprecated/file-box-pb.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.spec.js +0 -18
- package/dist/cjs/src/deprecated/file-box-pb.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.type.d.ts +0 -15
- package/dist/cjs/src/deprecated/file-box-pb.type.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.type.js +0 -3
- package/dist/cjs/src/deprecated/file-box-pb.type.js.map +0 -1
- package/dist/cjs/src/deprecated/mod.d.ts +0 -3
- package/dist/cjs/src/deprecated/mod.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/mod.js +0 -10
- package/dist/cjs/src/deprecated/mod.js.map +0 -1
- package/dist/cjs/src/deprecated/next-data.d.ts +0 -7
- package/dist/cjs/src/deprecated/next-data.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/next-data.js +0 -26
- package/dist/cjs/src/deprecated/next-data.js.map +0 -1
- package/dist/cjs/src/deprecated/serialize-file-box.d.ts +0 -6
- package/dist/cjs/src/deprecated/serialize-file-box.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/serialize-file-box.js +0 -22
- package/dist/cjs/src/deprecated/serialize-file-box.js.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.d.ts +0 -15
- package/dist/esm/src/deprecated/chunk-pb.d.ts.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.js +0 -56
- package/dist/esm/src/deprecated/chunk-pb.js.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.spec.js +0 -142
- package/dist/esm/src/deprecated/chunk-pb.spec.js.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.d.ts +0 -21
- package/dist/esm/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.js +0 -39
- package/dist/esm/src/deprecated/conversation-id-file-box.js.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.js +0 -92
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.d.ts +0 -14
- package/dist/esm/src/deprecated/file-box-chunk.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.js +0 -63
- package/dist/esm/src/deprecated/file-box-chunk.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.spec.js +0 -132
- package/dist/esm/src/deprecated/file-box-chunk.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.d.ts +0 -15
- package/dist/esm/src/deprecated/file-box-pb.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.js +0 -22
- package/dist/esm/src/deprecated/file-box-pb.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.spec.js +0 -16
- package/dist/esm/src/deprecated/file-box-pb.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.type.d.ts +0 -15
- package/dist/esm/src/deprecated/file-box-pb.type.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.type.js +0 -2
- package/dist/esm/src/deprecated/file-box-pb.type.js.map +0 -1
- package/dist/esm/src/deprecated/mod.d.ts +0 -3
- package/dist/esm/src/deprecated/mod.d.ts.map +0 -1
- package/dist/esm/src/deprecated/mod.js +0 -3
- package/dist/esm/src/deprecated/mod.js.map +0 -1
- package/dist/esm/src/deprecated/next-data.d.ts +0 -7
- package/dist/esm/src/deprecated/next-data.d.ts.map +0 -1
- package/dist/esm/src/deprecated/next-data.js +0 -23
- package/dist/esm/src/deprecated/next-data.js.map +0 -1
- package/dist/esm/src/deprecated/serialize-file-box.d.ts +0 -6
- package/dist/esm/src/deprecated/serialize-file-box.d.ts.map +0 -1
- package/dist/esm/src/deprecated/serialize-file-box.js +0 -18
- package/dist/esm/src/deprecated/serialize-file-box.js.map +0 -1
- package/src/deprecated/chunk-pb.spec.ts +0 -210
- package/src/deprecated/chunk-pb.ts +0 -75
- package/src/deprecated/conversation-id-file-box.spec.ts +0 -131
- package/src/deprecated/conversation-id-file-box.ts +0 -72
- package/src/deprecated/file-box-chunk.spec.ts +0 -184
- package/src/deprecated/file-box-chunk.ts +0 -87
- package/src/deprecated/file-box-pb.spec.ts +0 -31
- package/src/deprecated/file-box-pb.ts +0 -41
- package/src/deprecated/file-box-pb.type.ts +0 -16
- package/src/deprecated/mod.ts +0 -8
- package/src/deprecated/next-data.ts +0 -35
- package/src/deprecated/serialize-file-box.ts +0 -24
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
import util from 'util'
|
|
21
|
-
import type { Writable } from 'stream'
|
|
22
21
|
import * as PUPPET from '@juzi/wechaty-puppet'
|
|
23
22
|
|
|
24
23
|
import type {
|
|
@@ -40,15 +39,6 @@ import {
|
|
|
40
39
|
import type { Store } from 'redux'
|
|
41
40
|
// import type { Subscription } from 'rxjs'
|
|
42
41
|
|
|
43
|
-
/**
|
|
44
|
-
* Deprecated. Will be removed after Dec 31, 2022
|
|
45
|
-
*/
|
|
46
|
-
import {
|
|
47
|
-
packConversationIdFileBoxToPb,
|
|
48
|
-
unpackFileBoxFromPb,
|
|
49
|
-
} from '../deprecated/mod.js'
|
|
50
|
-
import { serializeFileBox } from '../deprecated/serialize-file-box.js'
|
|
51
|
-
|
|
52
42
|
import { millisecondsFromTimestamp } from '../pure-functions/timestamp.js'
|
|
53
43
|
|
|
54
44
|
import {
|
|
@@ -617,13 +607,6 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
617
607
|
const serializedFileBox = await this.serializeFileBox(fileBox)
|
|
618
608
|
request.setFileBox(serializedFileBox)
|
|
619
609
|
|
|
620
|
-
{
|
|
621
|
-
// DEPRECATED, will be removed after Dec 31, 2022
|
|
622
|
-
const fileboxWrapper = new StringValue()
|
|
623
|
-
fileboxWrapper.setValue(await serializeFileBox(fileBox))
|
|
624
|
-
request.setFileboxStringValueDeprecated(fileboxWrapper)
|
|
625
|
-
}
|
|
626
|
-
|
|
627
610
|
await util.promisify(
|
|
628
611
|
this.grpcManager.client.contactAvatar
|
|
629
612
|
.bind(this.grpcManager.client),
|
|
@@ -893,39 +876,22 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
893
876
|
imageType,
|
|
894
877
|
PUPPET.types.Image[imageType],
|
|
895
878
|
)
|
|
879
|
+
const request = new grpcPuppet.MessageImageRequest()
|
|
880
|
+
request.setId(messageId)
|
|
881
|
+
request.setType(imageType)
|
|
896
882
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const response = await util.promisify(
|
|
903
|
-
this.grpcManager.client.messageImage
|
|
904
|
-
.bind(this.grpcManager.client),
|
|
905
|
-
)(request)
|
|
906
|
-
|
|
907
|
-
const jsonText = response.getFileBox()
|
|
883
|
+
const response = await util.promisify(
|
|
884
|
+
this.grpcManager.client.messageImage
|
|
885
|
+
.bind(this.grpcManager.client),
|
|
886
|
+
)(request)
|
|
908
887
|
|
|
909
|
-
|
|
910
|
-
return this.FileBoxUuid.fromJSON(jsonText)
|
|
911
|
-
}
|
|
888
|
+
const jsonText = response.getFileBox()
|
|
912
889
|
|
|
913
|
-
|
|
914
|
-
|
|
890
|
+
if (jsonText) {
|
|
891
|
+
return this.FileBoxUuid.fromJSON(jsonText)
|
|
915
892
|
}
|
|
916
893
|
|
|
917
|
-
{
|
|
918
|
-
// Deprecated. Will be removed after Dec 31, 2022
|
|
919
|
-
const request = new grpcPuppet.MessageImageStreamRequest()
|
|
920
|
-
request.setId(messageId)
|
|
921
|
-
request.setType(imageType)
|
|
922
|
-
|
|
923
|
-
const pbStream = this.grpcManager.client.messageImageStream(request)
|
|
924
|
-
const fileBox = await unpackFileBoxFromPb(pbStream)
|
|
925
|
-
// const fileBoxChunkStream = unpackFileBoxChunk(stream)
|
|
926
|
-
// return unpackFileBox(fileBoxChunkStream)
|
|
927
|
-
return fileBox
|
|
928
|
-
}
|
|
894
|
+
throw new Error(`failed to get image filebox for message ${messageId}`)
|
|
929
895
|
}
|
|
930
896
|
|
|
931
897
|
override async messageContact (
|
|
@@ -1091,40 +1057,19 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
1091
1057
|
override async messageFile (id: string): Promise<FileBoxInterface> {
|
|
1092
1058
|
log.verbose('PuppetService', 'messageFile(%s)', id)
|
|
1093
1059
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
this.grpcManager.client
|
|
1099
|
-
|
|
1100
|
-
)(request)
|
|
1060
|
+
const request = new grpcPuppet.MessageFileRequest()
|
|
1061
|
+
request.setId(id)
|
|
1062
|
+
const response = await util.promisify(
|
|
1063
|
+
this.grpcManager.client.messageFile
|
|
1064
|
+
.bind(this.grpcManager.client),
|
|
1065
|
+
)(request)
|
|
1101
1066
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
} catch (e) {
|
|
1107
|
-
log.warn('PuppetService', 'messageFile() rejection: %s', (e as Error).message)
|
|
1108
|
-
log.warn('PuppetService', [
|
|
1109
|
-
'This might because you are using Wechaty v1.x with a Puppet Service v0.x',
|
|
1110
|
-
'Contact your Wechaty Puppet Service provided to report this problem',
|
|
1111
|
-
'Related issues:',
|
|
1112
|
-
' - https://github.com/wechaty/puppet-service/issues/179',
|
|
1113
|
-
' - https://github.com/wechaty/puppet-service/pull/170',
|
|
1114
|
-
].join('\n'))
|
|
1067
|
+
const jsonText = response.getFileBox()
|
|
1068
|
+
if (jsonText) {
|
|
1069
|
+
return this.FileBoxUuid.fromJSON(jsonText)
|
|
1115
1070
|
}
|
|
1116
1071
|
|
|
1117
|
-
{
|
|
1118
|
-
// Deprecated. `MessageFileStream` Will be removed after Dec 31, 2022
|
|
1119
|
-
const request = new grpcPuppet.MessageFileStreamRequest()
|
|
1120
|
-
request.setId(id)
|
|
1121
|
-
|
|
1122
|
-
const pbStream = this.grpcManager.client.messageFileStream(request)
|
|
1123
|
-
// const fileBoxChunkStream = unpackFileBoxChunk(pbStream)
|
|
1124
|
-
// return unpackFileBox(fileBoxChunkStream)
|
|
1125
|
-
const fileBox = await unpackFileBoxFromPb(pbStream)
|
|
1126
|
-
return fileBox
|
|
1127
|
-
}
|
|
1072
|
+
throw new Error(`failed to get filebox for message ${id}`)
|
|
1128
1073
|
}
|
|
1129
1074
|
|
|
1130
1075
|
override async messagePreview (id: string): Promise<FileBoxInterface | undefined> {
|
|
@@ -1286,47 +1231,32 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
1286
1231
|
): Promise<void | string> {
|
|
1287
1232
|
log.verbose('PuppetService', 'messageSendFile(%s, %s)', conversationId, fileBox)
|
|
1288
1233
|
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
request.setConversationId(conversationId)
|
|
1234
|
+
const request = new grpcPuppet.MessageSendFileRequest()
|
|
1235
|
+
request.setConversationId(conversationId)
|
|
1292
1236
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1237
|
+
const serializedFileBox = await this.serializeFileBox(fileBox)
|
|
1238
|
+
request.setFileBox(serializedFileBox)
|
|
1295
1239
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1240
|
+
log.info('PuppetService', `messageSendFile(${conversationId}, ${fileBox}) about to call grpc`)
|
|
1241
|
+
const response = await util.promisify(
|
|
1242
|
+
this.grpcManager.client.messageSendFile
|
|
1243
|
+
.bind(this.grpcManager.client),
|
|
1244
|
+
)(request)
|
|
1301
1245
|
|
|
1302
|
-
|
|
1303
|
-
|
|
1246
|
+
const messageId = response.getId()
|
|
1247
|
+
log.info('PuppetService', `messageSendFile(${conversationId}, ${fileBox}) grpc called, messageId: ${messageId}`)
|
|
1304
1248
|
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
}
|
|
1249
|
+
if (messageId) {
|
|
1250
|
+
return messageId
|
|
1251
|
+
} else {
|
|
1252
|
+
/**
|
|
1253
|
+
* Huan(202110): Deprecated: will be removed after Dec 31, 2022
|
|
1254
|
+
*/
|
|
1255
|
+
const messageIdWrapper = response.getIdStringValueDeprecated()
|
|
1256
|
+
if (messageIdWrapper) {
|
|
1257
|
+
return messageIdWrapper.getValue()
|
|
1315
1258
|
}
|
|
1316
|
-
|
|
1317
|
-
return // void
|
|
1318
|
-
|
|
1319
|
-
} catch (e) {
|
|
1320
|
-
log.verbose('PuppetService', 'messageSendFile() rejection: %s', (e as Error).message)
|
|
1321
1259
|
}
|
|
1322
|
-
|
|
1323
|
-
/**
|
|
1324
|
-
* Huan(202110): Deprecated: will be removed after Dec 31, 2022
|
|
1325
|
-
* The old server will not support `Upload` gRPC method,
|
|
1326
|
-
* which I'm expecting the above code will throw a exception,
|
|
1327
|
-
* then the below code will be executed.
|
|
1328
|
-
*/
|
|
1329
|
-
return this.messageSendFileStream(conversationId, fileBox)
|
|
1330
1260
|
}
|
|
1331
1261
|
|
|
1332
1262
|
override async messageSendContact (
|
|
@@ -1606,6 +1536,19 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
1606
1536
|
)(request)
|
|
1607
1537
|
}
|
|
1608
1538
|
|
|
1539
|
+
override async roomRemark (roomId: string, remark: string): Promise<void> {
|
|
1540
|
+
log.verbose('PuppetService', 'roomRemark(%s)', roomId)
|
|
1541
|
+
|
|
1542
|
+
const request = new grpcPuppet.RoomRemarkRequest()
|
|
1543
|
+
request.setId(roomId)
|
|
1544
|
+
request.setRemark(remark)
|
|
1545
|
+
|
|
1546
|
+
await util.promisify(
|
|
1547
|
+
this.grpcManager.client.roomRemark
|
|
1548
|
+
.bind(this.grpcManager.client),
|
|
1549
|
+
)(request)
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1609
1552
|
override async roomCreate (
|
|
1610
1553
|
contactIdList : string[],
|
|
1611
1554
|
topic : string,
|
|
@@ -2507,43 +2450,6 @@ class PuppetService extends PUPPET.Puppet {
|
|
|
2507
2450
|
return contactIdsList
|
|
2508
2451
|
}
|
|
2509
2452
|
|
|
2510
|
-
/**
|
|
2511
|
-
* @deprecated Will be removed in v2.0
|
|
2512
|
-
*/
|
|
2513
|
-
private async messageSendFileStream (
|
|
2514
|
-
conversationId : string,
|
|
2515
|
-
file : FileBoxInterface,
|
|
2516
|
-
): Promise<void | string> {
|
|
2517
|
-
const request = await packConversationIdFileBoxToPb(grpcPuppet.MessageSendFileStreamRequest)(conversationId, file)
|
|
2518
|
-
|
|
2519
|
-
const response = await new Promise<grpcPuppet.MessageSendFileStreamResponse>((resolve, reject) => {
|
|
2520
|
-
const stream = this.grpcManager.client.messageSendFileStream((err, response) => {
|
|
2521
|
-
if (err) {
|
|
2522
|
-
reject(err)
|
|
2523
|
-
} else {
|
|
2524
|
-
resolve(response)
|
|
2525
|
-
}
|
|
2526
|
-
})
|
|
2527
|
-
request.pipe(stream as unknown as Writable) // Huan(202203): FIXME: as unknown as
|
|
2528
|
-
})
|
|
2529
|
-
|
|
2530
|
-
const messageId = response.getId()
|
|
2531
|
-
|
|
2532
|
-
if (messageId) {
|
|
2533
|
-
return messageId
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
{
|
|
2537
|
-
/**
|
|
2538
|
-
* Huan(202110): Deprecated: will be removed after Dec 31, 2022
|
|
2539
|
-
*/
|
|
2540
|
-
const messageIdWrapper = response.getIdStringValueDeprecated()
|
|
2541
|
-
if (messageIdWrapper) {
|
|
2542
|
-
return messageIdWrapper.getValue()
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
|
|
2547
2453
|
healthCheckInterval?: NodeJS.Timer
|
|
2548
2454
|
startHealthCheck () {
|
|
2549
2455
|
this.healthCheckInterval = setInterval(() => {
|
package/src/package-json.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { PackageJson } from 'type-fest'
|
|
5
5
|
export const packageJson: PackageJson = {
|
|
6
6
|
"name": "@juzi/wechaty-puppet-service",
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.44",
|
|
8
8
|
"description": "Puppet Service for Wechaty",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
@@ -55,7 +55,7 @@ export const packageJson: PackageJson = {
|
|
|
55
55
|
"@chatie/eslint-config": "^1.0.4",
|
|
56
56
|
"@chatie/semver": "^0.4.7",
|
|
57
57
|
"@chatie/tsconfig": "^4.6.3",
|
|
58
|
-
"@juzi/wechaty-puppet": "^1.0.
|
|
58
|
+
"@juzi/wechaty-puppet": "^1.0.49",
|
|
59
59
|
"@juzi/wechaty-puppet-mock": "^1.0.1",
|
|
60
60
|
"@types/google-protobuf": "^3.15.5",
|
|
61
61
|
"@types/lru-cache": "^7.5.0",
|
|
@@ -73,7 +73,7 @@ export const packageJson: PackageJson = {
|
|
|
73
73
|
"@juzi/wechaty-puppet": "^1.0.46"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@juzi/wechaty-grpc": "^1.0.
|
|
76
|
+
"@juzi/wechaty-grpc": "^1.0.43",
|
|
77
77
|
"@juzi/wechaty-redux": "^1.0.1",
|
|
78
78
|
"clone-class": "^1.1.1",
|
|
79
79
|
"ducks": "^1.0.2",
|
|
@@ -34,11 +34,6 @@ import type {
|
|
|
34
34
|
import * as PUPPET from '@juzi/wechaty-puppet'
|
|
35
35
|
import { timeoutPromise } from 'gerror'
|
|
36
36
|
|
|
37
|
-
import {
|
|
38
|
-
packFileBoxToPb,
|
|
39
|
-
unpackConversationIdFileBoxArgsFromPb,
|
|
40
|
-
} from '../deprecated/mod.js'
|
|
41
|
-
|
|
42
37
|
import {
|
|
43
38
|
timestampFromMilliseconds,
|
|
44
39
|
} from '../pure-functions/timestamp.js'
|
|
@@ -630,27 +625,6 @@ function puppetImplementation (
|
|
|
630
625
|
}
|
|
631
626
|
},
|
|
632
627
|
|
|
633
|
-
/**
|
|
634
|
-
* @deprecated will be removed after Dec 31, 2022
|
|
635
|
-
*/
|
|
636
|
-
messageFileStream: async (call) => {
|
|
637
|
-
log.verbose('PuppetServiceImpl', 'messageFileStream()')
|
|
638
|
-
|
|
639
|
-
try {
|
|
640
|
-
const id = call.request.getId()
|
|
641
|
-
|
|
642
|
-
const fileBox = await puppet.messageFile(id)
|
|
643
|
-
const response = await packFileBoxToPb(grpcPuppet.MessageFileStreamResponse)(fileBox)
|
|
644
|
-
|
|
645
|
-
response.on('error', e => call.destroy(e as Error))
|
|
646
|
-
response.pipe(call as unknown as Writable) // Huan(202203): FIXME: as unknown as
|
|
647
|
-
|
|
648
|
-
} catch (e) {
|
|
649
|
-
log.error('PuppetServiceImpl', 'grpcError() messageFileStream() rejection: %s', e && (e as Error).message)
|
|
650
|
-
call.destroy(e as Error)
|
|
651
|
-
}
|
|
652
|
-
},
|
|
653
|
-
|
|
654
628
|
messageForward: async (call, callback) => {
|
|
655
629
|
log.verbose('PuppetServiceImpl', 'messageForward()')
|
|
656
630
|
|
|
@@ -700,28 +674,6 @@ function puppetImplementation (
|
|
|
700
674
|
}
|
|
701
675
|
},
|
|
702
676
|
|
|
703
|
-
/**
|
|
704
|
-
* @deprecated will be removed after Dec 31, 2022
|
|
705
|
-
*/
|
|
706
|
-
messageImageStream: async (call) => {
|
|
707
|
-
log.verbose('PuppetServiceImpl', 'messageImageStream()')
|
|
708
|
-
|
|
709
|
-
try {
|
|
710
|
-
const id = call.request.getId()
|
|
711
|
-
const type = call.request.getType()
|
|
712
|
-
|
|
713
|
-
const fileBox = await puppet.messageImage(id, type) // as number as PUPPET.types.Image
|
|
714
|
-
const response = await packFileBoxToPb(grpcPuppet.MessageImageStreamResponse)(fileBox)
|
|
715
|
-
|
|
716
|
-
response.on('error', e => call.destroy(e as Error))
|
|
717
|
-
response.pipe(call as unknown as Writable) // Huan(202203) FIXME: as unknown as
|
|
718
|
-
|
|
719
|
-
} catch (e) {
|
|
720
|
-
log.error('PuppetServiceImpl', 'grpcError() messageImageStream() rejection: %s', (e as Error).message)
|
|
721
|
-
call.destroy(e as Error)
|
|
722
|
-
}
|
|
723
|
-
},
|
|
724
|
-
|
|
725
677
|
messageLocation: async (call, callback) => {
|
|
726
678
|
log.verbose('PuppetServiceImpl', 'messageLocation()')
|
|
727
679
|
|
|
@@ -942,40 +894,6 @@ function puppetImplementation (
|
|
|
942
894
|
}
|
|
943
895
|
},
|
|
944
896
|
|
|
945
|
-
/**
|
|
946
|
-
* @deprecated will be removed after Dec 31, 2022
|
|
947
|
-
*/
|
|
948
|
-
messageSendFileStream: async (call, callback) => {
|
|
949
|
-
log.verbose('PuppetServiceImpl', 'messageSendFileStream()')
|
|
950
|
-
|
|
951
|
-
try {
|
|
952
|
-
const requestArgs = await unpackConversationIdFileBoxArgsFromPb(call)
|
|
953
|
-
const conversationId = requestArgs.conversationId
|
|
954
|
-
const fileBox = requestArgs.fileBox
|
|
955
|
-
|
|
956
|
-
const messageId = await puppet.messageSendFile(conversationId, fileBox)
|
|
957
|
-
|
|
958
|
-
const response = new grpcPuppet.MessageSendFileStreamResponse()
|
|
959
|
-
|
|
960
|
-
if (messageId) {
|
|
961
|
-
response.setId(messageId)
|
|
962
|
-
{
|
|
963
|
-
/**
|
|
964
|
-
* Huan(202110): Deprecated: will be removed after Dec 31, 2022
|
|
965
|
-
*/
|
|
966
|
-
const idWrapper = new StringValue()
|
|
967
|
-
idWrapper.setValue(messageId)
|
|
968
|
-
response.setIdStringValueDeprecated(idWrapper)
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
return callback(null, response)
|
|
973
|
-
|
|
974
|
-
} catch (e) {
|
|
975
|
-
return grpcError('messageSendFileStream', e, callback)
|
|
976
|
-
}
|
|
977
|
-
},
|
|
978
|
-
|
|
979
897
|
messageSendLocation: async (call, callback) => {
|
|
980
898
|
log.verbose('PuppetServiceImpl', 'messageSendLocation()')
|
|
981
899
|
|
|
@@ -1521,6 +1439,22 @@ function puppetImplementation (
|
|
|
1521
1439
|
}
|
|
1522
1440
|
},
|
|
1523
1441
|
|
|
1442
|
+
roomRemark: async (call, callback) => {
|
|
1443
|
+
log.verbose('PuppetServiceImpl', 'roomRemark()')
|
|
1444
|
+
|
|
1445
|
+
try {
|
|
1446
|
+
const roomId = call.request.getId()
|
|
1447
|
+
const remark = call.request.getRemark()
|
|
1448
|
+
|
|
1449
|
+
await puppet.roomRemark(roomId, remark)
|
|
1450
|
+
|
|
1451
|
+
return callback(null, new grpcPuppet.RoomRemarkResponse())
|
|
1452
|
+
|
|
1453
|
+
} catch (e) {
|
|
1454
|
+
return grpcError('roomRemark', e, callback)
|
|
1455
|
+
}
|
|
1456
|
+
},
|
|
1457
|
+
|
|
1524
1458
|
start: async (call, callback) => {
|
|
1525
1459
|
log.verbose('PuppetServiceImpl', 'start()')
|
|
1526
1460
|
void call
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { puppet } from '@juzi/wechaty-grpc';
|
|
2
|
-
import { Readable } from 'stronger-typed-streams';
|
|
3
|
-
import type { FileBoxPb } from './file-box-pb.type.js';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
6
|
-
*/
|
|
7
|
-
declare function packFileBoxChunkToPb<T extends FileBoxPb>(PbConstructor: {
|
|
8
|
-
new (): T;
|
|
9
|
-
}): (stream: Readable<puppet.FileBoxChunk>) => Readable<T>;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
12
|
-
*/
|
|
13
|
-
declare function unpackFileBoxChunkFromPb<T extends FileBoxPb>(stream: Readable<T>): Readable<puppet.FileBoxChunk>;
|
|
14
|
-
export { packFileBoxChunkToPb, unpackFileBoxChunkFromPb, };
|
|
15
|
-
//# sourceMappingURL=chunk-pb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-pb.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/chunk-pb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAa,MAAM,wBAAwB,CAAA;AAG5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAiBtD;;GAEG;AACH,iBAAS,oBAAoB,CAAC,CAAC,SAAS,SAAS,EAC/C,aAAa,EAAE;IAAE,QAAO,CAAC,CAAA;CAAE,YAEX,SAAS,OAAO,YAAY,CAAC,KAAG,SAAS,CAAC,CAAC,CAU5D;AAkBD;;GAEG;AACH,iBAAS,wBAAwB,CAAC,CAAC,SAAS,SAAS,EACnD,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAClB,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAS/B;AAED,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,CAAA"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unpackFileBoxChunkFromPb = exports.packFileBoxChunkToPb = void 0;
|
|
4
|
-
const stronger_typed_streams_1 = require("stronger-typed-streams");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
/**
|
|
7
|
-
* Wrap FileBoxChunk
|
|
8
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
9
|
-
*/
|
|
10
|
-
const encoder = (PbConstructor) => new stronger_typed_streams_1.Transform({
|
|
11
|
-
objectMode: true,
|
|
12
|
-
transform: (chunk, _, callback) => {
|
|
13
|
-
const message = new PbConstructor();
|
|
14
|
-
message.setFileBoxChunk(chunk);
|
|
15
|
-
callback(null, message);
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
20
|
-
*/
|
|
21
|
-
function packFileBoxChunkToPb(PbConstructor) {
|
|
22
|
-
return (stream) => {
|
|
23
|
-
const outStream = new stream_1.PassThrough({ objectMode: true });
|
|
24
|
-
const encodedStream = stream.pipe(encoder(PbConstructor));
|
|
25
|
-
stream.on('error', e => outStream.emit('error', e));
|
|
26
|
-
encodedStream.on('error', e => outStream.emit('error', e));
|
|
27
|
-
encodedStream.pipe(outStream);
|
|
28
|
-
return outStream;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.packFileBoxChunkToPb = packFileBoxChunkToPb;
|
|
32
|
-
/**
|
|
33
|
-
* Unwrap FileBoxChunk
|
|
34
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
35
|
-
*/
|
|
36
|
-
const decoder = () => new stronger_typed_streams_1.Transform({
|
|
37
|
-
objectMode: true,
|
|
38
|
-
transform: (chunk, _, callback) => {
|
|
39
|
-
const fileBoxChunk = chunk.getFileBoxChunk();
|
|
40
|
-
if (!fileBoxChunk) {
|
|
41
|
-
callback(new Error('No FileBoxChunk'));
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
callback(null, fileBoxChunk);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
50
|
-
*/
|
|
51
|
-
function unpackFileBoxChunkFromPb(stream) {
|
|
52
|
-
const outStream = new stream_1.PassThrough({ objectMode: true });
|
|
53
|
-
const decodedStream = stream.pipe(decoder());
|
|
54
|
-
stream.on('error', e => outStream.emit('error', e));
|
|
55
|
-
decodedStream.on('error', e => outStream.emit('error', e));
|
|
56
|
-
decodedStream.pipe(outStream);
|
|
57
|
-
return outStream;
|
|
58
|
-
}
|
|
59
|
-
exports.unpackFileBoxChunkFromPb = unpackFileBoxChunkFromPb;
|
|
60
|
-
//# sourceMappingURL=chunk-pb.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-pb.js","sourceRoot":"","sources":["../../../../src/deprecated/chunk-pb.ts"],"names":[],"mappings":";;;AACA,mEAA4D;AAC5D,mCAAoC;AAIpC;;;GAGG;AACH,MAAM,OAAO,GAAG,CACd,aAA2B,EAC3B,EAAE,CAAC,IAAI,kCAAS,CAAyB;IACzC,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,CAAC,KAA0B,EAAE,CAAM,EAAE,QAAgD,EAAE,EAAE;QAClG,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAA;QACnC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC;CACF,CAAC,CAAA;AAEF;;GAEG;AACH,SAAS,oBAAoB,CAC3B,aAA2B;IAE3B,OAAO,CAAC,MAAqC,EAAe,EAAE;QAC5D,MAAM,SAAS,GAAO,IAAI,oBAAW,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;QAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;QAEzD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;QAC1D,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;QAE1D,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC7B,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;AACH,CAAC;AAmCC,oDAAoB;AAjCtB;;;GAGG;AACH,MAAM,OAAO,GAAG,GAAwB,EAAE,CAAC,IAAI,kCAAS,CAAyB;IAC/E,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,CAAC,KAAQ,EAAE,CAAM,EAAE,QAAmE,EAAE,EAAE;QACnG,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,EAAE,CAAA;QAC5C,IAAI,CAAC,YAAY,EAAE;YACjB,QAAQ,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;SACvC;aAAM;YACL,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;SAC7B;IACH,CAAC;CACF,CAAC,CAAA;AAEF;;GAEG;AACH,SAAS,wBAAwB,CAC/B,MAAmB;IAEnB,MAAM,SAAS,GAAO,IAAI,oBAAW,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IAE5C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;IAC1D,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;IAE1D,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC7B,OAAO,SAAS,CAAA;AAClB,CAAC;AAIC,4DAAwB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-pb.spec.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/chunk-pb.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tstest_1 = require("tstest");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
const file_box_1 = require("file-box");
|
|
7
|
-
const wechaty_grpc_1 = require("@juzi/wechaty-grpc");
|
|
8
|
-
const file_box_chunk_js_1 = require("./file-box-chunk.js");
|
|
9
|
-
const chunk_pb_js_1 = require("./chunk-pb.js");
|
|
10
|
-
(0, tstest_1.test)('packFileBoxChunk()', async (t) => {
|
|
11
|
-
const FILE_BOX_DATA = 'test';
|
|
12
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
13
|
-
const fileBox = file_box_1.FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
14
|
-
const chunkStream = await (0, file_box_chunk_js_1.packFileBoxToChunk)(fileBox);
|
|
15
|
-
const pbStream = await (0, chunk_pb_js_1.packFileBoxChunkToPb)(wechaty_grpc_1.puppet.MessageFileStreamResponse)(chunkStream);
|
|
16
|
-
let name = '';
|
|
17
|
-
let buffer = '';
|
|
18
|
-
pbStream.on('data', (data) => {
|
|
19
|
-
if (data.hasFileBoxChunk()) {
|
|
20
|
-
const fileBoxChunk = data.getFileBoxChunk();
|
|
21
|
-
if (fileBoxChunk.hasData()) {
|
|
22
|
-
buffer += fileBoxChunk.getData();
|
|
23
|
-
}
|
|
24
|
-
else if (fileBoxChunk.hasName()) {
|
|
25
|
-
name = fileBoxChunk.getName();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
await new Promise(resolve => chunkStream.on('end', resolve));
|
|
30
|
-
t.equal(name, FILE_BOX_NAME, 'should get file box name');
|
|
31
|
-
t.equal(buffer, FILE_BOX_DATA, 'should get file box data');
|
|
32
|
-
});
|
|
33
|
-
(0, tstest_1.test)('unpackFileBoxChunkFromPb()', async (t) => {
|
|
34
|
-
const FILE_BOX_DATA = 'test';
|
|
35
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
36
|
-
const fileBox = file_box_1.FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
37
|
-
const chunkStream = await (0, file_box_chunk_js_1.packFileBoxToChunk)(fileBox);
|
|
38
|
-
const request = new wechaty_grpc_1.puppet.MessageSendFileStreamRequest();
|
|
39
|
-
const packedStream = new stream_1.PassThrough({ objectMode: true });
|
|
40
|
-
chunkStream.on('data', (data) => {
|
|
41
|
-
request.setFileBoxChunk(data);
|
|
42
|
-
packedStream.write(request);
|
|
43
|
-
}).on('end', () => {
|
|
44
|
-
packedStream.end();
|
|
45
|
-
});
|
|
46
|
-
const outputChunkStream = (0, chunk_pb_js_1.unpackFileBoxChunkFromPb)(packedStream);
|
|
47
|
-
const outputFileBox = await (0, file_box_chunk_js_1.unpackFileBoxFromChunk)(outputChunkStream);
|
|
48
|
-
t.equal((await outputFileBox.toBuffer()).toString(), FILE_BOX_DATA, 'should get file box data');
|
|
49
|
-
});
|
|
50
|
-
(0, tstest_1.test)('packFileBoxChunk() <-> unpackFileBoxChunkFromPb()', async (t) => {
|
|
51
|
-
const FILE_BOX_DATA = 'test';
|
|
52
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
53
|
-
const fileBox = file_box_1.FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
54
|
-
const chunkStream = await (0, file_box_chunk_js_1.packFileBoxToChunk)(fileBox);
|
|
55
|
-
const packedStream = (0, chunk_pb_js_1.packFileBoxChunkToPb)(wechaty_grpc_1.puppet.MessageFileStreamResponse)(chunkStream);
|
|
56
|
-
const unpackedStream = (0, chunk_pb_js_1.unpackFileBoxChunkFromPb)(packedStream);
|
|
57
|
-
const restoredBox = await (0, file_box_chunk_js_1.unpackFileBoxFromChunk)(unpackedStream);
|
|
58
|
-
t.equal(fileBox.name, restoredBox.name, 'should be same name');
|
|
59
|
-
const EXPECTED_BASE64 = await fileBox.toBase64();
|
|
60
|
-
const actualBase64 = await restoredBox.toBase64();
|
|
61
|
-
t.equal(EXPECTED_BASE64, actualBase64, 'should be same content');
|
|
62
|
-
});
|
|
63
|
-
(0, tstest_1.test)('packFileBoxChunk(): should not throw if no read on the stream', async (t) => {
|
|
64
|
-
t.plan(1);
|
|
65
|
-
const stream = await getTestChunkStream({});
|
|
66
|
-
let outStream;
|
|
67
|
-
try {
|
|
68
|
-
outStream = (0, chunk_pb_js_1.packFileBoxChunkToPb)(wechaty_grpc_1.puppet.MessageFileStreamResponse)(stream);
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
t.ok(e.message);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
outStream.on('error', _ => { });
|
|
75
|
-
t.pass();
|
|
76
|
-
});
|
|
77
|
-
(0, tstest_1.test)('packFileBoxChunk(): should emit error in the output stream', async (t) => {
|
|
78
|
-
const EXPECTED_MESSAGE = 'test emit error';
|
|
79
|
-
const stream = await getTestChunkStream({ errorMessage: EXPECTED_MESSAGE });
|
|
80
|
-
const outStream = (0, chunk_pb_js_1.packFileBoxChunkToPb)(wechaty_grpc_1.puppet.MessageFileStreamResponse)(stream);
|
|
81
|
-
const error = await new Promise(resolve => outStream.on('error', resolve));
|
|
82
|
-
// await new Promise(resolve => outStream.on('end', resolve))
|
|
83
|
-
t.equal(error.message, EXPECTED_MESSAGE, 'should emit error message');
|
|
84
|
-
});
|
|
85
|
-
(0, tstest_1.test)('unpackFileBoxChunkFromPb(): should not throw if no read on the stream', async (t) => {
|
|
86
|
-
t.plan(1);
|
|
87
|
-
const stream = await getTestPackedStream({});
|
|
88
|
-
let outStream;
|
|
89
|
-
try {
|
|
90
|
-
outStream = (0, chunk_pb_js_1.unpackFileBoxChunkFromPb)(stream);
|
|
91
|
-
t.pass('should no rejection');
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
t.fail(e.message);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
outStream.on('error', _ => { });
|
|
98
|
-
});
|
|
99
|
-
(0, tstest_1.test)('unpackFileBoxChunkFromPb(): should emit error in the output stream', async (t) => {
|
|
100
|
-
const errorMessage = 'test emit error';
|
|
101
|
-
const stream = await getTestPackedStream({ errorMessage });
|
|
102
|
-
const outStream = (0, chunk_pb_js_1.packFileBoxChunkToPb)(wechaty_grpc_1.puppet.MessageFileStreamResponse)(stream);
|
|
103
|
-
try {
|
|
104
|
-
await new Promise((resolve, reject) => {
|
|
105
|
-
outStream.on('error', reject);
|
|
106
|
-
outStream.on('end', resolve);
|
|
107
|
-
});
|
|
108
|
-
t.fail('should reject the promise');
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
t.equal(e.message, errorMessage, 'should get the expected rejection error message');
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
async function getTestChunkStream(options) {
|
|
115
|
-
const { errorMessage } = options;
|
|
116
|
-
const FILE_BOX_DATA = 'test';
|
|
117
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
118
|
-
const fileBox = file_box_1.FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
119
|
-
const chunkStream = await (0, file_box_chunk_js_1.packFileBoxToChunk)(fileBox);
|
|
120
|
-
setImmediate(() => {
|
|
121
|
-
chunkStream.emit('error', new Error(errorMessage));
|
|
122
|
-
});
|
|
123
|
-
return chunkStream;
|
|
124
|
-
}
|
|
125
|
-
async function getTestPackedStream(options) {
|
|
126
|
-
const { errorMessage } = options;
|
|
127
|
-
const FILE_BOX_DATA = 'test';
|
|
128
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
129
|
-
const fileBox = file_box_1.FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
130
|
-
const chunkStream = await (0, file_box_chunk_js_1.packFileBoxToChunk)(fileBox);
|
|
131
|
-
const packedStream = new stream_1.PassThrough({ objectMode: true });
|
|
132
|
-
chunkStream.on('data', d => {
|
|
133
|
-
const packedChunk = new wechaty_grpc_1.puppet.MessageFileStreamResponse();
|
|
134
|
-
packedChunk.setFileBoxChunk(d);
|
|
135
|
-
packedStream.write(packedChunk);
|
|
136
|
-
}).on('error', e => {
|
|
137
|
-
packedStream.emit('error', e);
|
|
138
|
-
});
|
|
139
|
-
setImmediate(() => {
|
|
140
|
-
chunkStream.emit('error', new Error(errorMessage));
|
|
141
|
-
});
|
|
142
|
-
return packedStream;
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=chunk-pb.spec.js.map
|