@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.
Files changed (128) hide show
  1. package/dist/cjs/src/client/puppet-service.d.ts +1 -4
  2. package/dist/cjs/src/client/puppet-service.d.ts.map +1 -1
  3. package/dist/cjs/src/client/puppet-service.js +47 -129
  4. package/dist/cjs/src/client/puppet-service.js.map +1 -1
  5. package/dist/cjs/src/package-json.js +3 -3
  6. package/dist/cjs/src/server/puppet-implementation.d.ts.map +1 -1
  7. package/dist/cjs/src/server/puppet-implementation.js +14 -66
  8. package/dist/cjs/src/server/puppet-implementation.js.map +1 -1
  9. package/dist/esm/src/client/puppet-service.d.ts +1 -4
  10. package/dist/esm/src/client/puppet-service.d.ts.map +1 -1
  11. package/dist/esm/src/client/puppet-service.js +44 -126
  12. package/dist/esm/src/client/puppet-service.js.map +1 -1
  13. package/dist/esm/src/package-json.js +3 -3
  14. package/dist/esm/src/server/puppet-implementation.d.ts.map +1 -1
  15. package/dist/esm/src/server/puppet-implementation.js +12 -64
  16. package/dist/esm/src/server/puppet-implementation.js.map +1 -1
  17. package/package.json +3 -3
  18. package/src/client/puppet-service.ts +54 -148
  19. package/src/package-json.ts +3 -3
  20. package/src/server/puppet-implementation.ts +16 -82
  21. package/dist/cjs/src/deprecated/chunk-pb.d.ts +0 -15
  22. package/dist/cjs/src/deprecated/chunk-pb.d.ts.map +0 -1
  23. package/dist/cjs/src/deprecated/chunk-pb.js +0 -60
  24. package/dist/cjs/src/deprecated/chunk-pb.js.map +0 -1
  25. package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts +0 -3
  26. package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
  27. package/dist/cjs/src/deprecated/chunk-pb.spec.js +0 -144
  28. package/dist/cjs/src/deprecated/chunk-pb.spec.js.map +0 -1
  29. package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts +0 -21
  30. package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
  31. package/dist/cjs/src/deprecated/conversation-id-file-box.js +0 -43
  32. package/dist/cjs/src/deprecated/conversation-id-file-box.js.map +0 -1
  33. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
  34. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
  35. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js +0 -94
  36. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
  37. package/dist/cjs/src/deprecated/file-box-chunk.d.ts +0 -14
  38. package/dist/cjs/src/deprecated/file-box-chunk.d.ts.map +0 -1
  39. package/dist/cjs/src/deprecated/file-box-chunk.js +0 -67
  40. package/dist/cjs/src/deprecated/file-box-chunk.js.map +0 -1
  41. package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts +0 -3
  42. package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
  43. package/dist/cjs/src/deprecated/file-box-chunk.spec.js +0 -134
  44. package/dist/cjs/src/deprecated/file-box-chunk.spec.js.map +0 -1
  45. package/dist/cjs/src/deprecated/file-box-pb.d.ts +0 -15
  46. package/dist/cjs/src/deprecated/file-box-pb.d.ts.map +0 -1
  47. package/dist/cjs/src/deprecated/file-box-pb.js +0 -26
  48. package/dist/cjs/src/deprecated/file-box-pb.js.map +0 -1
  49. package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts +0 -3
  50. package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
  51. package/dist/cjs/src/deprecated/file-box-pb.spec.js +0 -18
  52. package/dist/cjs/src/deprecated/file-box-pb.spec.js.map +0 -1
  53. package/dist/cjs/src/deprecated/file-box-pb.type.d.ts +0 -15
  54. package/dist/cjs/src/deprecated/file-box-pb.type.d.ts.map +0 -1
  55. package/dist/cjs/src/deprecated/file-box-pb.type.js +0 -3
  56. package/dist/cjs/src/deprecated/file-box-pb.type.js.map +0 -1
  57. package/dist/cjs/src/deprecated/mod.d.ts +0 -3
  58. package/dist/cjs/src/deprecated/mod.d.ts.map +0 -1
  59. package/dist/cjs/src/deprecated/mod.js +0 -10
  60. package/dist/cjs/src/deprecated/mod.js.map +0 -1
  61. package/dist/cjs/src/deprecated/next-data.d.ts +0 -7
  62. package/dist/cjs/src/deprecated/next-data.d.ts.map +0 -1
  63. package/dist/cjs/src/deprecated/next-data.js +0 -26
  64. package/dist/cjs/src/deprecated/next-data.js.map +0 -1
  65. package/dist/cjs/src/deprecated/serialize-file-box.d.ts +0 -6
  66. package/dist/cjs/src/deprecated/serialize-file-box.d.ts.map +0 -1
  67. package/dist/cjs/src/deprecated/serialize-file-box.js +0 -22
  68. package/dist/cjs/src/deprecated/serialize-file-box.js.map +0 -1
  69. package/dist/esm/src/deprecated/chunk-pb.d.ts +0 -15
  70. package/dist/esm/src/deprecated/chunk-pb.d.ts.map +0 -1
  71. package/dist/esm/src/deprecated/chunk-pb.js +0 -56
  72. package/dist/esm/src/deprecated/chunk-pb.js.map +0 -1
  73. package/dist/esm/src/deprecated/chunk-pb.spec.d.ts +0 -3
  74. package/dist/esm/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
  75. package/dist/esm/src/deprecated/chunk-pb.spec.js +0 -142
  76. package/dist/esm/src/deprecated/chunk-pb.spec.js.map +0 -1
  77. package/dist/esm/src/deprecated/conversation-id-file-box.d.ts +0 -21
  78. package/dist/esm/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
  79. package/dist/esm/src/deprecated/conversation-id-file-box.js +0 -39
  80. package/dist/esm/src/deprecated/conversation-id-file-box.js.map +0 -1
  81. package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
  82. package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
  83. package/dist/esm/src/deprecated/conversation-id-file-box.spec.js +0 -92
  84. package/dist/esm/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
  85. package/dist/esm/src/deprecated/file-box-chunk.d.ts +0 -14
  86. package/dist/esm/src/deprecated/file-box-chunk.d.ts.map +0 -1
  87. package/dist/esm/src/deprecated/file-box-chunk.js +0 -63
  88. package/dist/esm/src/deprecated/file-box-chunk.js.map +0 -1
  89. package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts +0 -3
  90. package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
  91. package/dist/esm/src/deprecated/file-box-chunk.spec.js +0 -132
  92. package/dist/esm/src/deprecated/file-box-chunk.spec.js.map +0 -1
  93. package/dist/esm/src/deprecated/file-box-pb.d.ts +0 -15
  94. package/dist/esm/src/deprecated/file-box-pb.d.ts.map +0 -1
  95. package/dist/esm/src/deprecated/file-box-pb.js +0 -22
  96. package/dist/esm/src/deprecated/file-box-pb.js.map +0 -1
  97. package/dist/esm/src/deprecated/file-box-pb.spec.d.ts +0 -3
  98. package/dist/esm/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
  99. package/dist/esm/src/deprecated/file-box-pb.spec.js +0 -16
  100. package/dist/esm/src/deprecated/file-box-pb.spec.js.map +0 -1
  101. package/dist/esm/src/deprecated/file-box-pb.type.d.ts +0 -15
  102. package/dist/esm/src/deprecated/file-box-pb.type.d.ts.map +0 -1
  103. package/dist/esm/src/deprecated/file-box-pb.type.js +0 -2
  104. package/dist/esm/src/deprecated/file-box-pb.type.js.map +0 -1
  105. package/dist/esm/src/deprecated/mod.d.ts +0 -3
  106. package/dist/esm/src/deprecated/mod.d.ts.map +0 -1
  107. package/dist/esm/src/deprecated/mod.js +0 -3
  108. package/dist/esm/src/deprecated/mod.js.map +0 -1
  109. package/dist/esm/src/deprecated/next-data.d.ts +0 -7
  110. package/dist/esm/src/deprecated/next-data.d.ts.map +0 -1
  111. package/dist/esm/src/deprecated/next-data.js +0 -23
  112. package/dist/esm/src/deprecated/next-data.js.map +0 -1
  113. package/dist/esm/src/deprecated/serialize-file-box.d.ts +0 -6
  114. package/dist/esm/src/deprecated/serialize-file-box.d.ts.map +0 -1
  115. package/dist/esm/src/deprecated/serialize-file-box.js +0 -18
  116. package/dist/esm/src/deprecated/serialize-file-box.js.map +0 -1
  117. package/src/deprecated/chunk-pb.spec.ts +0 -210
  118. package/src/deprecated/chunk-pb.ts +0 -75
  119. package/src/deprecated/conversation-id-file-box.spec.ts +0 -131
  120. package/src/deprecated/conversation-id-file-box.ts +0 -72
  121. package/src/deprecated/file-box-chunk.spec.ts +0 -184
  122. package/src/deprecated/file-box-chunk.ts +0 -87
  123. package/src/deprecated/file-box-pb.spec.ts +0 -31
  124. package/src/deprecated/file-box-pb.ts +0 -41
  125. package/src/deprecated/file-box-pb.type.ts +0 -16
  126. package/src/deprecated/mod.ts +0 -8
  127. package/src/deprecated/next-data.ts +0 -35
  128. package/src/deprecated/serialize-file-box.ts +0 -24
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
- /**
3
- * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
4
- *
5
- * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
6
- * Wechaty Contributors <https://github.com/wechaty>.
7
- *
8
- * Licensed under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- *
20
- */
21
- import { test } from 'tstest';
22
- import { PassThrough } from 'stream';
23
- import { FileBox } from 'file-box';
24
- import { puppet, } from '@juzi/wechaty-grpc';
25
- import { unpackFileBoxFromChunk, packFileBoxToChunk, } from './file-box-chunk.js';
26
- import { nextData } from './next-data.js';
27
- test('unpackFileBoxFromChunk()', async (t) => {
28
- const FILE_BOX_DATA = 'test';
29
- const FILE_BOX_NAME = 'test.dat';
30
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME);
31
- const decodedFileBox = await unpackFileBoxFromChunk(stream);
32
- const data = (await decodedFileBox.toBuffer()).toString();
33
- t.equal(decodedFileBox.name, FILE_BOX_NAME, 'should get file box name');
34
- t.equal(data, FILE_BOX_DATA, 'should get file box data');
35
- });
36
- test('packFileBoxToChunk()', async (t) => {
37
- const FILE_BOX_DATA = 'test';
38
- const FILE_BOX_NAME = 'test.dat';
39
- const fileBox = FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
40
- const stream = await packFileBoxToChunk(fileBox);
41
- const fileBoxChunk = await nextData(stream);
42
- t.ok(fileBoxChunk.hasName(), 'has name');
43
- const fileName = fileBoxChunk.getName();
44
- t.equal(fileName, FILE_BOX_NAME, 'should get name');
45
- let data = '';
46
- stream.on('data', (chunk) => {
47
- if (!chunk.hasData()) {
48
- throw new Error('no data');
49
- }
50
- data += chunk.getData();
51
- });
52
- await new Promise(resolve => stream.on('end', resolve));
53
- t.equal(data, FILE_BOX_DATA, 'should get file box data');
54
- });
55
- test('packFileBoxToChunk() <-> unpackFileBoxFromChunk()', async (t) => {
56
- const FILE_BOX_DATA = 'test';
57
- const FILE_BOX_NAME = 'test.dat';
58
- const fileBox = FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
59
- const stream = await packFileBoxToChunk(fileBox);
60
- const restoredBox = await unpackFileBoxFromChunk(stream);
61
- t.equal(fileBox.name, restoredBox.name, 'should be same name');
62
- t.equal(await fileBox.toBase64(), await restoredBox.toBase64(), 'should be same content');
63
- });
64
- test('should handle no name error in catch', async (t) => {
65
- t.plan(1);
66
- const FILE_BOX_DATA = 'test';
67
- const FILE_BOX_NAME = 'test.dat';
68
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, true);
69
- try {
70
- await unpackFileBoxFromChunk(stream);
71
- }
72
- catch (e) {
73
- t.equal(e.message, 'no name');
74
- }
75
- });
76
- test('should handle first error catch', async (t) => {
77
- t.plan(1);
78
- const FILE_BOX_DATA = 'test';
79
- const FILE_BOX_NAME = 'test.dat';
80
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, false, true);
81
- try {
82
- await unpackFileBoxFromChunk(stream);
83
- }
84
- catch (e) {
85
- t.equal(e.message, 'first exception');
86
- }
87
- });
88
- test('should handle middle error in further ops', async (t) => {
89
- t.plan(1);
90
- const FILE_BOX_DATA = 'test';
91
- const FILE_BOX_NAME = 'test.dat';
92
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, false, false, true);
93
- const fileBox = await unpackFileBoxFromChunk(stream);
94
- try {
95
- await fileBox.toBuffer();
96
- }
97
- catch (e) {
98
- t.equal(e.message, 'middle exception');
99
- }
100
- });
101
- async function getFileBoxStreamStub(data, name, noname = false, firstException = false, middleException = false) {
102
- const fileBox = FileBox.fromBuffer(Buffer.from(data), name);
103
- const stream = new PassThrough({ objectMode: true });
104
- if (firstException) {
105
- stream.pause();
106
- setImmediate(() => {
107
- stream.emit('error', new Error('first exception'));
108
- stream.resume();
109
- });
110
- }
111
- else {
112
- const chunk1 = new puppet.FileBoxChunk();
113
- if (!noname) {
114
- chunk1.setName(fileBox.name);
115
- }
116
- setTimeout(() => stream.write(chunk1), 10);
117
- }
118
- if (middleException) {
119
- setTimeout(() => {
120
- stream.emit('error', new Error('middle exception'));
121
- }, 100);
122
- }
123
- const fileBoxStream = await fileBox.toStream();
124
- fileBoxStream.on('data', chunk => {
125
- const fileBoxChunk = new puppet.FileBoxChunk();
126
- fileBoxChunk.setData(chunk);
127
- setTimeout(() => stream.write(fileBoxChunk), 200);
128
- });
129
- fileBoxStream.on('end', () => setTimeout(() => stream.end(), 250));
130
- return stream;
131
- }
132
- //# sourceMappingURL=file-box-chunk.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-chunk.spec.js","sourceRoot":"","sources":["../../../../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A;KAC3C;IAED,IAAI,eAAe,EAAE;QACnB,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAA;QACrD,CAAC,EAAE,GAAG,CAAC,CAAA;KACR;IAED,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;IAC9C,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;QAC/B,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,YAAY,EAAE,CAAA;QAC9C,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;IACF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;IAElE,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,15 +0,0 @@
1
- import type { FileBoxInterface } from 'file-box';
2
- import type { 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 packFileBoxToPb<T extends FileBoxPb>(PbConstructor: {
8
- new (): T;
9
- }): (fileBox: FileBoxInterface) => Promise<Readable<T>>;
10
- /**
11
- * @deprecated Will be removed after Dec 31, 2022
12
- */
13
- declare function unpackFileBoxFromPb<T extends FileBoxPb>(pbStream: Readable<T>): Promise<FileBoxInterface>;
14
- export { packFileBoxToPb, unpackFileBoxFromPb, };
15
- //# sourceMappingURL=file-box-pb.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAW,UAAU,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAU,wBAAwB,CAAA;AAU1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAa,uBAAuB,CAAA;AAE7D;;GAEG;AACH,iBAAS,eAAe,CAAC,CAAC,SAAS,SAAS,EAC1C,aAAa,EAAE;IAAE,QAAO,CAAC,CAAA;CAAE,aAEJ,gBAAgB,0BAKxC;AAED;;GAEG;AACH,iBAAe,mBAAmB,CAAC,CAAC,SAAS,SAAS,EACpD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,gBAAgB,CAAC,CAI3B;AAED,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,CAAA"}
@@ -1,22 +0,0 @@
1
- import { packFileBoxToChunk, unpackFileBoxFromChunk, } from './file-box-chunk.js';
2
- import { packFileBoxChunkToPb, unpackFileBoxChunkFromPb, } from './chunk-pb.js';
3
- /**
4
- * @deprecated Will be removed after Dec 31, 2022
5
- */
6
- function packFileBoxToPb(PbConstructor) {
7
- return async (fileBox) => {
8
- const fileBoxChunkStream = await packFileBoxToChunk(fileBox);
9
- const pbFileBox = packFileBoxChunkToPb(PbConstructor)(fileBoxChunkStream);
10
- return pbFileBox;
11
- };
12
- }
13
- /**
14
- * @deprecated Will be removed after Dec 31, 2022
15
- */
16
- async function unpackFileBoxFromPb(pbStream) {
17
- const fileBoxChunkStream = unpackFileBoxChunkFromPb(pbStream);
18
- const fileBox = await unpackFileBoxFromChunk(fileBoxChunkStream);
19
- return fileBox;
20
- }
21
- export { packFileBoxToPb, unpackFileBoxFromPb, };
22
- //# sourceMappingURL=file-box-pb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.js","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAgC,qBAAqB,CAAA;AACtD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAgC,eAAe,CAAA;AAGhD;;GAEG;AACH,SAAS,eAAe,CACtB,aAA2B;IAE3B,OAAO,KAAK,EAAE,OAAyB,EAAE,EAAE;QACzC,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAA;QAC5D,MAAM,SAAS,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC,kBAAkB,CAAC,CAAA;QACzE,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,mBAAmB,CAChC,QAAqB;IAErB,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAA;IAC7D,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;IAChE,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,CAAA"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
- export {};
3
- //# sourceMappingURL=file-box-pb.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.spec.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.spec.ts"],"names":[],"mappings":""}
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
- import { test } from 'tstest';
3
- import { FileBox } from 'file-box';
4
- import { puppet, } from '@juzi/wechaty-grpc';
5
- import { packFileBoxToPb, unpackFileBoxFromPb, } from './file-box-pb.js';
6
- test('packFileBoxToPb()', async (t) => {
7
- const FILE_BOX_DATA = 'test';
8
- const FILE_BOX_NAME = 'test.dat';
9
- const fileBox = FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
10
- const pb = await packFileBoxToPb(puppet.MessageFileStreamResponse)(fileBox);
11
- const restoredFileBox = await unpackFileBoxFromPb(pb);
12
- t.ok(restoredFileBox instanceof FileBox, 'should get an instance of FileBOX');
13
- t.equal(restoredFileBox.name, fileBox.name, 'should get the right file box name');
14
- t.equal(await restoredFileBox.toBase64(), await fileBox.toBase64(), 'should get the right file box content');
15
- });
16
- //# sourceMappingURL=file-box-pb.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.spec.js","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.spec.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,OAAO,EACL,MAAM,GACP,MAAsC,oBAAoB,CAAA;AAE3D,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAAkC,kBAAkB,CAAA;AAErD,IAAI,CAAC,mBAAmB,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAClC,MAAM,aAAa,GAAG,MAAM,CAAA;IAC5B,MAAM,aAAa,GAAG,UAAU,CAAA;IAEhC,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAChC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAC1B,aAAa,CACd,CAAA;IAED,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,OAAO,CAAC,CAAA;IAC3E,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,EAAE,CAAC,CAAA;IACrD,CAAC,CAAC,EAAE,CAAC,eAAe,YAAY,OAAO,EAAE,mCAAmC,CAAC,CAAA;IAE7E,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAA;IACjF,CAAC,CAAC,KAAK,CAAC,MAAM,eAAe,CAAC,QAAQ,EAAE,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,uCAAuC,CAAC,CAAA;AAC9G,CAAC,CAAC,CAAA"}
@@ -1,15 +0,0 @@
1
- import type { puppet } from '@juzi/wechaty-grpc';
2
- /**
3
- * Any Protocol Buffer message that include a FileBoxChunk
4
- */
5
- export interface FileBoxPb {
6
- hasFileBoxChunk(): boolean;
7
- getFileBoxChunk(): puppet.FileBoxChunk | undefined;
8
- setFileBoxChunk(value?: puppet.FileBoxChunk): void;
9
- }
10
- export interface ConversationIdFileBoxPb extends FileBoxPb {
11
- hasConversationId(): boolean;
12
- getConversationId(): string;
13
- setConversationId(value: string): void;
14
- }
15
- //# sourceMappingURL=file-box-pb.type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.type.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,IAAI,OAAO,CAAA;IAC1B,eAAe,IAAI,MAAM,CAAC,YAAY,GAAG,SAAS,CAAA;IAClD,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,YAAY,GAAG,IAAI,CAAA;CACnD;AAED,MAAM,WAAW,uBAAwB,SAAQ,SAAS;IACxD,iBAAiB,IAAI,OAAO,CAAA;IAC5B,iBAAiB,IAAI,MAAM,CAAA;IAC3B,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=file-box-pb.type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-box-pb.type.js","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.type.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export { packConversationIdFileBoxToPb, unpackConversationIdFileBoxArgsFromPb, } from './conversation-id-file-box.js';
2
- export { packFileBoxToPb, unpackFileBoxFromPb, } from './file-box-pb.js';
3
- //# sourceMappingURL=mod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,GACtC,MAA8C,+BAA+B,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAA8C,kBAAkB,CAAA"}
@@ -1,3 +0,0 @@
1
- export { packConversationIdFileBoxToPb, unpackConversationIdFileBoxArgsFromPb, } from './conversation-id-file-box.js';
2
- export { packFileBoxToPb, unpackFileBoxFromPb, } from './file-box-pb.js';
3
- //# sourceMappingURL=mod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../../src/deprecated/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,GACtC,MAA8C,+BAA+B,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAA8C,kBAAkB,CAAA"}
@@ -1,7 +0,0 @@
1
- import type { Readable } from 'stronger-typed-streams';
2
- /**
3
- * @deprecated Will be removed after Dec 31, 2022
4
- */
5
- declare function nextData<T>(stream: Readable<T>): Promise<T>;
6
- export { nextData, };
7
- //# sourceMappingURL=next-data.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next-data.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/next-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACT,MAAgB,wBAAwB,CAAA;AAQzC;;GAEG;AACH,iBAAe,QAAQ,CAAC,CAAC,EACvB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,CAeZ;AAED,OAAO,EACL,QAAQ,GACT,CAAA"}
@@ -1,23 +0,0 @@
1
- /**
2
- * windmemory(20201027): generating fileBox data in server side might take longer.
3
- * Set to 60 sec to avoid unexpected timeout.
4
- */
5
- const TIMEOUT = 60 * 1000;
6
- /**
7
- * @deprecated Will be removed after Dec 31, 2022
8
- */
9
- async function nextData(stream) {
10
- const chunk = await new Promise((resolve, reject) => {
11
- const timer = setTimeout(reject, TIMEOUT);
12
- stream.once('data', chunk => {
13
- stream.pause();
14
- clearTimeout(timer);
15
- resolve(chunk);
16
- });
17
- stream.once('error', reject);
18
- });
19
- stream.resume();
20
- return chunk;
21
- }
22
- export { nextData, };
23
- //# sourceMappingURL=next-data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next-data.js","sourceRoot":"","sources":["../../../../src/deprecated/next-data.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,GAAG,EAAE,GAAG,IAAI,CAAA;AAEzB;;GAEG;AACH,KAAK,UAAU,QAAQ,CACrB,MAAmB;IAEnB,MAAM,KAAK,GAAG,MAAM,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YAC1B,MAAM,CAAC,KAAK,EAAE,CAAA;YACd,YAAY,CAAC,KAAK,CAAC,CAAA;YAEnB,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAE9B,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,MAAM,EAAE,CAAA;IACf,OAAO,KAAK,CAAA;AACd,CAAC;AAED,OAAO,EACL,QAAQ,GACT,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { FileBoxInterface } from 'file-box';
2
- /**
3
- * @deprecated Will be removed after Dec 31, 2022
4
- */
5
- export declare const serializeFileBox: (fileBox: FileBoxInterface) => Promise<string>;
6
- //# sourceMappingURL=serialize-file-box.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialize-file-box.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/serialize-file-box.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EACjB,MAA0B,UAAU,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,gBAAgB,YAAmB,gBAAgB,KAAG,QAAQ,MAAM,CAYhF,CAAA"}
@@ -1,18 +0,0 @@
1
- import { FileBox, FileBoxType, } from 'file-box';
2
- /**
3
- * @deprecated Will be removed after Dec 31, 2022
4
- */
5
- export const serializeFileBox = async (fileBox) => {
6
- const serializableFileBoxTypes = [
7
- FileBoxType.Base64,
8
- FileBoxType.Url,
9
- FileBoxType.QRCode,
10
- ];
11
- if (serializableFileBoxTypes.includes(fileBox.type)) {
12
- return JSON.stringify(fileBox);
13
- }
14
- const base64 = await fileBox.toBase64();
15
- const name = fileBox.name;
16
- return JSON.stringify(FileBox.fromBase64(base64, name));
17
- };
18
- //# sourceMappingURL=serialize-file-box.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialize-file-box.js","sourceRoot":"","sources":["../../../../src/deprecated/serialize-file-box.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,GACZ,MAA0B,UAAU,CAAA;AAKrC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,OAAyB,EAAmB,EAAE;IACnF,MAAM,wBAAwB,GAAG;QAC/B,WAAW,CAAC,MAAM;QAClB,WAAW,CAAC,GAAG;QACf,WAAW,CAAC,MAAM;KACnB,CAAA;IACD,IAAI,wBAAwB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;KAC/B;IACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IACzB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA"}
@@ -1,210 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
-
3
- import { test } from 'tstest'
4
-
5
- import { PassThrough } from 'stream'
6
-
7
- import { FileBox } from 'file-box'
8
-
9
- import {
10
- puppet,
11
- } from '@juzi/wechaty-grpc'
12
-
13
- import {
14
- unpackFileBoxFromChunk,
15
- packFileBoxToChunk,
16
- } from './file-box-chunk.js'
17
- import {
18
- unpackFileBoxChunkFromPb,
19
- packFileBoxChunkToPb,
20
- } from './chunk-pb.js'
21
-
22
- test('packFileBoxChunk()', async t => {
23
- const FILE_BOX_DATA = 'test'
24
- const FILE_BOX_NAME = 'test.dat'
25
-
26
- const fileBox = FileBox.fromBuffer(
27
- Buffer.from(FILE_BOX_DATA),
28
- FILE_BOX_NAME,
29
- )
30
-
31
- const chunkStream = await packFileBoxToChunk(fileBox)
32
- const pbStream = await packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(chunkStream)
33
-
34
- let name = ''
35
- let buffer = ''
36
- pbStream.on('data', (data: puppet.MessageFileStreamResponse) => {
37
- if (data.hasFileBoxChunk()) {
38
- const fileBoxChunk = data.getFileBoxChunk()
39
- if (fileBoxChunk!.hasData()) {
40
- buffer += fileBoxChunk!.getData()
41
- } else if (fileBoxChunk!.hasName()) {
42
- name = fileBoxChunk!.getName()
43
- }
44
- }
45
- })
46
-
47
- await new Promise(resolve => chunkStream.on('end', resolve))
48
- t.equal(name, FILE_BOX_NAME, 'should get file box name')
49
- t.equal(buffer, FILE_BOX_DATA, 'should get file box data')
50
-
51
- })
52
-
53
- test('unpackFileBoxChunkFromPb()', async t => {
54
- const FILE_BOX_DATA = 'test'
55
- const FILE_BOX_NAME = 'test.dat'
56
-
57
- const fileBox = FileBox.fromBuffer(
58
- Buffer.from(FILE_BOX_DATA),
59
- FILE_BOX_NAME,
60
- )
61
-
62
- const chunkStream = await packFileBoxToChunk(fileBox)
63
- const request = new puppet.MessageSendFileStreamRequest()
64
-
65
- const packedStream = new PassThrough({ objectMode: true })
66
-
67
- chunkStream.on('data', (data: puppet.FileBoxChunk) => {
68
- request.setFileBoxChunk(data)
69
- packedStream.write(request)
70
- }).on('end', () => {
71
- packedStream.end()
72
- })
73
-
74
- const outputChunkStream = unpackFileBoxChunkFromPb(packedStream)
75
- const outputFileBox = await unpackFileBoxFromChunk(outputChunkStream)
76
-
77
- t.equal((await outputFileBox.toBuffer()).toString(), FILE_BOX_DATA, 'should get file box data')
78
- })
79
-
80
- test('packFileBoxChunk() <-> unpackFileBoxChunkFromPb()', async t => {
81
- const FILE_BOX_DATA = 'test'
82
- const FILE_BOX_NAME = 'test.dat'
83
-
84
- const fileBox = FileBox.fromBuffer(
85
- Buffer.from(FILE_BOX_DATA),
86
- FILE_BOX_NAME,
87
- )
88
-
89
- const chunkStream = await packFileBoxToChunk(fileBox)
90
- const packedStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(chunkStream)
91
-
92
- const unpackedStream = unpackFileBoxChunkFromPb(packedStream)
93
- const restoredBox = await unpackFileBoxFromChunk(unpackedStream)
94
- t.equal(fileBox.name, restoredBox.name, 'should be same name')
95
-
96
- const EXPECTED_BASE64 = await fileBox.toBase64()
97
- const actualBase64 = await restoredBox.toBase64()
98
-
99
- t.equal(EXPECTED_BASE64, actualBase64, 'should be same content')
100
- })
101
-
102
- test('packFileBoxChunk(): should not throw if no read on the stream', async t => {
103
-
104
- t.plan(1)
105
- const stream = await getTestChunkStream({})
106
- let outStream
107
- try {
108
- outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
109
- } catch (e) {
110
- t.ok((e as Error).message)
111
- return
112
- }
113
- outStream.on('error', _ => { /* Do nothing */ })
114
- t.pass()
115
- })
116
-
117
- test('packFileBoxChunk(): should emit error in the output stream', async t => {
118
- const EXPECTED_MESSAGE = 'test emit error'
119
-
120
- const stream = await getTestChunkStream({ errorMessage: EXPECTED_MESSAGE })
121
- const outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
122
-
123
- const error = await new Promise<Error>(resolve => outStream.on('error', resolve))
124
- // await new Promise(resolve => outStream.on('end', resolve))
125
- t.equal(error.message, EXPECTED_MESSAGE, 'should emit error message')
126
- })
127
-
128
- test('unpackFileBoxChunkFromPb(): should not throw if no read on the stream', async t => {
129
-
130
- t.plan(1)
131
- const stream = await getTestPackedStream({})
132
- let outStream
133
- try {
134
- outStream = unpackFileBoxChunkFromPb(stream)
135
- t.pass('should no rejection')
136
- } catch (e) {
137
- t.fail((e as Error).message)
138
- return
139
- }
140
- outStream.on('error', _ => { /* Do nothing */ })
141
- })
142
-
143
- test('unpackFileBoxChunkFromPb(): should emit error in the output stream', async t => {
144
-
145
- const errorMessage = 'test emit error'
146
- const stream = await getTestPackedStream({ errorMessage })
147
-
148
- const outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
149
-
150
- try {
151
- await new Promise((resolve, reject) => {
152
- outStream.on('error', reject)
153
- outStream.on('end', resolve)
154
- })
155
- t.fail('should reject the promise')
156
- } catch (e) {
157
- t.equal((e as Error).message, errorMessage, 'should get the expected rejection error message')
158
- }
159
- })
160
-
161
- async function getTestChunkStream (options: {
162
- errorMessage?: string,
163
- }) {
164
- const { errorMessage } = options
165
-
166
- const FILE_BOX_DATA = 'test'
167
- const FILE_BOX_NAME = 'test.dat'
168
-
169
- const fileBox = FileBox.fromBuffer(
170
- Buffer.from(FILE_BOX_DATA),
171
- FILE_BOX_NAME,
172
- )
173
-
174
- const chunkStream = await packFileBoxToChunk(fileBox)
175
- setImmediate(() => {
176
- chunkStream.emit('error', new Error(errorMessage))
177
- })
178
-
179
- return chunkStream
180
- }
181
-
182
- async function getTestPackedStream (options: {
183
- errorMessage?: string,
184
- }) {
185
- const { errorMessage } = options
186
-
187
- const FILE_BOX_DATA = 'test'
188
- const FILE_BOX_NAME = 'test.dat'
189
-
190
- const fileBox = FileBox.fromBuffer(
191
- Buffer.from(FILE_BOX_DATA),
192
- FILE_BOX_NAME,
193
- )
194
-
195
- const chunkStream = await packFileBoxToChunk(fileBox)
196
- const packedStream = new PassThrough({ objectMode: true })
197
- chunkStream.on('data', d => {
198
- const packedChunk = new puppet.MessageFileStreamResponse()
199
- packedChunk.setFileBoxChunk(d)
200
- packedStream.write(packedChunk)
201
- }).on('error', e => {
202
- packedStream.emit('error', e)
203
- })
204
-
205
- setImmediate(() => {
206
- chunkStream.emit('error', new Error(errorMessage))
207
- })
208
-
209
- return packedStream
210
- }
@@ -1,75 +0,0 @@
1
- import type { puppet } from '@juzi/wechaty-grpc'
2
- import { Readable, Transform } from 'stronger-typed-streams'
3
- import { PassThrough } from 'stream'
4
-
5
- import type { FileBoxPb } from './file-box-pb.type.js'
6
-
7
- /**
8
- * Wrap FileBoxChunk
9
- * @deprecated Will be removed after Dec 31, 2022
10
- */
11
- const encoder = <T extends FileBoxPb>(
12
- PbConstructor: { new(): T },
13
- ) => new Transform<puppet.FileBoxChunk, T>({
14
- objectMode: true,
15
- transform: (chunk: puppet.FileBoxChunk, _: any, callback: (error: Error | null, data: T) => void) => {
16
- const message = new PbConstructor()
17
- message.setFileBoxChunk(chunk)
18
- callback(null, message)
19
- },
20
- })
21
-
22
- /**
23
- * @deprecated Will be removed after Dec 31, 2022
24
- */
25
- function packFileBoxChunkToPb<T extends FileBoxPb> (
26
- PbConstructor: { new(): T },
27
- ) {
28
- return (stream: Readable<puppet.FileBoxChunk>): Readable<T> => {
29
- const outStream = new PassThrough({ objectMode: true })
30
- const encodedStream = stream.pipe(encoder(PbConstructor))
31
-
32
- stream.on('error', e => outStream.emit('error', e))
33
- encodedStream.on('error', e => outStream.emit('error', e))
34
-
35
- encodedStream.pipe(outStream)
36
- return outStream
37
- }
38
- }
39
-
40
- /**
41
- * Unwrap FileBoxChunk
42
- * @deprecated Will be removed after Dec 31, 2022
43
- */
44
- const decoder = <T extends FileBoxPb>() => new Transform<T, puppet.FileBoxChunk>({
45
- objectMode: true,
46
- transform: (chunk: T, _: any, callback: (error: Error | null, data?: puppet.FileBoxChunk) => void) => {
47
- const fileBoxChunk = chunk.getFileBoxChunk()
48
- if (!fileBoxChunk) {
49
- callback(new Error('No FileBoxChunk'))
50
- } else {
51
- callback(null, fileBoxChunk)
52
- }
53
- },
54
- })
55
-
56
- /**
57
- * @deprecated Will be removed after Dec 31, 2022
58
- */
59
- function unpackFileBoxChunkFromPb<T extends FileBoxPb> (
60
- stream: Readable<T>,
61
- ): Readable<puppet.FileBoxChunk> {
62
- const outStream = new PassThrough({ objectMode: true })
63
- const decodedStream = stream.pipe(decoder())
64
-
65
- stream.on('error', e => outStream.emit('error', e))
66
- decodedStream.on('error', e => outStream.emit('error', e))
67
-
68
- decodedStream.pipe(outStream)
69
- return outStream
70
- }
71
-
72
- export {
73
- packFileBoxChunkToPb,
74
- unpackFileBoxChunkFromPb,
75
- }