@juzi/wechaty-puppet-service 1.0.43 → 1.0.45

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 (141) hide show
  1. package/dist/cjs/src/client/puppet-service.d.ts +3 -4
  2. package/dist/cjs/src/client/puppet-service.d.ts.map +1 -1
  3. package/dist/cjs/src/client/puppet-service.js +80 -198
  4. package/dist/cjs/src/client/puppet-service.js.map +1 -1
  5. package/dist/cjs/src/package-json.d.ts.map +1 -1
  6. package/dist/cjs/src/package-json.js +4 -3
  7. package/dist/cjs/src/package-json.js.map +1 -1
  8. package/dist/cjs/src/server/puppet-implementation.d.ts.map +1 -1
  9. package/dist/cjs/src/server/puppet-implementation.js +41 -127
  10. package/dist/cjs/src/server/puppet-implementation.js.map +1 -1
  11. package/dist/cjs/src/utils/pb-payload-helper.d.ts +5 -2
  12. package/dist/cjs/src/utils/pb-payload-helper.d.ts.map +1 -1
  13. package/dist/cjs/src/utils/pb-payload-helper.js +146 -1
  14. package/dist/cjs/src/utils/pb-payload-helper.js.map +1 -1
  15. package/dist/esm/src/client/puppet-service.d.ts +3 -4
  16. package/dist/esm/src/client/puppet-service.d.ts.map +1 -1
  17. package/dist/esm/src/client/puppet-service.js +78 -196
  18. package/dist/esm/src/client/puppet-service.js.map +1 -1
  19. package/dist/esm/src/package-json.d.ts.map +1 -1
  20. package/dist/esm/src/package-json.js +4 -3
  21. package/dist/esm/src/package-json.js.map +1 -1
  22. package/dist/esm/src/server/puppet-implementation.d.ts.map +1 -1
  23. package/dist/esm/src/server/puppet-implementation.js +40 -126
  24. package/dist/esm/src/server/puppet-implementation.js.map +1 -1
  25. package/dist/esm/src/utils/pb-payload-helper.d.ts +5 -2
  26. package/dist/esm/src/utils/pb-payload-helper.d.ts.map +1 -1
  27. package/dist/esm/src/utils/pb-payload-helper.js +120 -0
  28. package/dist/esm/src/utils/pb-payload-helper.js.map +1 -1
  29. package/package.json +4 -3
  30. package/src/client/puppet-service.ts +97 -214
  31. package/src/package-json.ts +4 -3
  32. package/src/server/puppet-implementation.ts +50 -144
  33. package/src/utils/pb-payload-helper.ts +119 -2
  34. package/dist/cjs/src/deprecated/chunk-pb.d.ts +0 -15
  35. package/dist/cjs/src/deprecated/chunk-pb.d.ts.map +0 -1
  36. package/dist/cjs/src/deprecated/chunk-pb.js +0 -60
  37. package/dist/cjs/src/deprecated/chunk-pb.js.map +0 -1
  38. package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts +0 -3
  39. package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
  40. package/dist/cjs/src/deprecated/chunk-pb.spec.js +0 -144
  41. package/dist/cjs/src/deprecated/chunk-pb.spec.js.map +0 -1
  42. package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts +0 -21
  43. package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
  44. package/dist/cjs/src/deprecated/conversation-id-file-box.js +0 -43
  45. package/dist/cjs/src/deprecated/conversation-id-file-box.js.map +0 -1
  46. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
  47. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
  48. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js +0 -94
  49. package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
  50. package/dist/cjs/src/deprecated/file-box-chunk.d.ts +0 -14
  51. package/dist/cjs/src/deprecated/file-box-chunk.d.ts.map +0 -1
  52. package/dist/cjs/src/deprecated/file-box-chunk.js +0 -67
  53. package/dist/cjs/src/deprecated/file-box-chunk.js.map +0 -1
  54. package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts +0 -3
  55. package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
  56. package/dist/cjs/src/deprecated/file-box-chunk.spec.js +0 -134
  57. package/dist/cjs/src/deprecated/file-box-chunk.spec.js.map +0 -1
  58. package/dist/cjs/src/deprecated/file-box-pb.d.ts +0 -15
  59. package/dist/cjs/src/deprecated/file-box-pb.d.ts.map +0 -1
  60. package/dist/cjs/src/deprecated/file-box-pb.js +0 -26
  61. package/dist/cjs/src/deprecated/file-box-pb.js.map +0 -1
  62. package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts +0 -3
  63. package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
  64. package/dist/cjs/src/deprecated/file-box-pb.spec.js +0 -18
  65. package/dist/cjs/src/deprecated/file-box-pb.spec.js.map +0 -1
  66. package/dist/cjs/src/deprecated/file-box-pb.type.d.ts +0 -15
  67. package/dist/cjs/src/deprecated/file-box-pb.type.d.ts.map +0 -1
  68. package/dist/cjs/src/deprecated/file-box-pb.type.js +0 -3
  69. package/dist/cjs/src/deprecated/file-box-pb.type.js.map +0 -1
  70. package/dist/cjs/src/deprecated/mod.d.ts +0 -3
  71. package/dist/cjs/src/deprecated/mod.d.ts.map +0 -1
  72. package/dist/cjs/src/deprecated/mod.js +0 -10
  73. package/dist/cjs/src/deprecated/mod.js.map +0 -1
  74. package/dist/cjs/src/deprecated/next-data.d.ts +0 -7
  75. package/dist/cjs/src/deprecated/next-data.d.ts.map +0 -1
  76. package/dist/cjs/src/deprecated/next-data.js +0 -26
  77. package/dist/cjs/src/deprecated/next-data.js.map +0 -1
  78. package/dist/cjs/src/deprecated/serialize-file-box.d.ts +0 -6
  79. package/dist/cjs/src/deprecated/serialize-file-box.d.ts.map +0 -1
  80. package/dist/cjs/src/deprecated/serialize-file-box.js +0 -22
  81. package/dist/cjs/src/deprecated/serialize-file-box.js.map +0 -1
  82. package/dist/esm/src/deprecated/chunk-pb.d.ts +0 -15
  83. package/dist/esm/src/deprecated/chunk-pb.d.ts.map +0 -1
  84. package/dist/esm/src/deprecated/chunk-pb.js +0 -56
  85. package/dist/esm/src/deprecated/chunk-pb.js.map +0 -1
  86. package/dist/esm/src/deprecated/chunk-pb.spec.d.ts +0 -3
  87. package/dist/esm/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
  88. package/dist/esm/src/deprecated/chunk-pb.spec.js +0 -142
  89. package/dist/esm/src/deprecated/chunk-pb.spec.js.map +0 -1
  90. package/dist/esm/src/deprecated/conversation-id-file-box.d.ts +0 -21
  91. package/dist/esm/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
  92. package/dist/esm/src/deprecated/conversation-id-file-box.js +0 -39
  93. package/dist/esm/src/deprecated/conversation-id-file-box.js.map +0 -1
  94. package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
  95. package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
  96. package/dist/esm/src/deprecated/conversation-id-file-box.spec.js +0 -92
  97. package/dist/esm/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
  98. package/dist/esm/src/deprecated/file-box-chunk.d.ts +0 -14
  99. package/dist/esm/src/deprecated/file-box-chunk.d.ts.map +0 -1
  100. package/dist/esm/src/deprecated/file-box-chunk.js +0 -63
  101. package/dist/esm/src/deprecated/file-box-chunk.js.map +0 -1
  102. package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts +0 -3
  103. package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
  104. package/dist/esm/src/deprecated/file-box-chunk.spec.js +0 -132
  105. package/dist/esm/src/deprecated/file-box-chunk.spec.js.map +0 -1
  106. package/dist/esm/src/deprecated/file-box-pb.d.ts +0 -15
  107. package/dist/esm/src/deprecated/file-box-pb.d.ts.map +0 -1
  108. package/dist/esm/src/deprecated/file-box-pb.js +0 -22
  109. package/dist/esm/src/deprecated/file-box-pb.js.map +0 -1
  110. package/dist/esm/src/deprecated/file-box-pb.spec.d.ts +0 -3
  111. package/dist/esm/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
  112. package/dist/esm/src/deprecated/file-box-pb.spec.js +0 -16
  113. package/dist/esm/src/deprecated/file-box-pb.spec.js.map +0 -1
  114. package/dist/esm/src/deprecated/file-box-pb.type.d.ts +0 -15
  115. package/dist/esm/src/deprecated/file-box-pb.type.d.ts.map +0 -1
  116. package/dist/esm/src/deprecated/file-box-pb.type.js +0 -2
  117. package/dist/esm/src/deprecated/file-box-pb.type.js.map +0 -1
  118. package/dist/esm/src/deprecated/mod.d.ts +0 -3
  119. package/dist/esm/src/deprecated/mod.d.ts.map +0 -1
  120. package/dist/esm/src/deprecated/mod.js +0 -3
  121. package/dist/esm/src/deprecated/mod.js.map +0 -1
  122. package/dist/esm/src/deprecated/next-data.d.ts +0 -7
  123. package/dist/esm/src/deprecated/next-data.d.ts.map +0 -1
  124. package/dist/esm/src/deprecated/next-data.js +0 -23
  125. package/dist/esm/src/deprecated/next-data.js.map +0 -1
  126. package/dist/esm/src/deprecated/serialize-file-box.d.ts +0 -6
  127. package/dist/esm/src/deprecated/serialize-file-box.d.ts.map +0 -1
  128. package/dist/esm/src/deprecated/serialize-file-box.js +0 -18
  129. package/dist/esm/src/deprecated/serialize-file-box.js.map +0 -1
  130. package/src/deprecated/chunk-pb.spec.ts +0 -210
  131. package/src/deprecated/chunk-pb.ts +0 -75
  132. package/src/deprecated/conversation-id-file-box.spec.ts +0 -131
  133. package/src/deprecated/conversation-id-file-box.ts +0 -72
  134. package/src/deprecated/file-box-chunk.spec.ts +0 -184
  135. package/src/deprecated/file-box-chunk.ts +0 -87
  136. package/src/deprecated/file-box-pb.spec.ts +0 -31
  137. package/src/deprecated/file-box-pb.ts +0 -41
  138. package/src/deprecated/file-box-pb.type.ts +0 -16
  139. package/src/deprecated/mod.ts +0 -8
  140. package/src/deprecated/next-data.ts +0 -35
  141. package/src/deprecated/serialize-file-box.ts +0 -24
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
-
3
- /**
4
- * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
5
- *
6
- * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
7
- * Wechaty Contributors <https://github.com/wechaty>.
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- *
21
- */
22
- import { test } from 'tstest'
23
-
24
- import { PassThrough } from 'stream'
25
- import type { Duplex } from 'stronger-typed-streams'
26
- import { FileBox } from 'file-box'
27
-
28
- import {
29
- puppet,
30
- } from '@juzi/wechaty-grpc'
31
-
32
- import {
33
- unpackFileBoxFromChunk,
34
- packFileBoxToChunk,
35
- } from './file-box-chunk.js'
36
- import { nextData } from './next-data.js'
37
-
38
- test('unpackFileBoxFromChunk()', async t => {
39
- const FILE_BOX_DATA = 'test'
40
- const FILE_BOX_NAME = 'test.dat'
41
-
42
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME)
43
-
44
- const decodedFileBox = await unpackFileBoxFromChunk(stream)
45
- const data = (await decodedFileBox.toBuffer()).toString()
46
-
47
- t.equal(decodedFileBox.name, FILE_BOX_NAME, 'should get file box name')
48
- t.equal(data, FILE_BOX_DATA, 'should get file box data')
49
-
50
- })
51
-
52
- test('packFileBoxToChunk()', async t => {
53
- const FILE_BOX_DATA = 'test'
54
- const FILE_BOX_NAME = 'test.dat'
55
-
56
- const fileBox = FileBox.fromBuffer(
57
- Buffer.from(FILE_BOX_DATA),
58
- FILE_BOX_NAME,
59
- )
60
-
61
- const stream = await packFileBoxToChunk(fileBox)
62
-
63
- const fileBoxChunk = await nextData(stream)
64
- t.ok(fileBoxChunk.hasName(), 'has name')
65
-
66
- const fileName = fileBoxChunk.getName()
67
- t.equal(fileName, FILE_BOX_NAME, 'should get name')
68
-
69
- let data = ''
70
- stream.on('data', (chunk: puppet.FileBoxChunk) => {
71
- if (!chunk.hasData()) {
72
- throw new Error('no data')
73
- }
74
- data += chunk.getData()
75
- })
76
-
77
- await new Promise(resolve => stream.on('end', resolve))
78
-
79
- t.equal(data, FILE_BOX_DATA, 'should get file box data')
80
- })
81
-
82
- test('packFileBoxToChunk() <-> unpackFileBoxFromChunk()', async t => {
83
- const FILE_BOX_DATA = 'test'
84
- const FILE_BOX_NAME = 'test.dat'
85
-
86
- const fileBox = FileBox.fromBuffer(
87
- Buffer.from(FILE_BOX_DATA),
88
- FILE_BOX_NAME,
89
- )
90
-
91
- const stream = await packFileBoxToChunk(fileBox)
92
- const restoredBox = await unpackFileBoxFromChunk(stream)
93
-
94
- t.equal(fileBox.name, restoredBox.name, 'should be same name')
95
- t.equal(await fileBox.toBase64(), await restoredBox.toBase64(), 'should be same content')
96
- })
97
-
98
- test('should handle no name error in catch', async t => {
99
- t.plan(1)
100
- const FILE_BOX_DATA = 'test'
101
- const FILE_BOX_NAME = 'test.dat'
102
-
103
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, true)
104
-
105
- try {
106
- await unpackFileBoxFromChunk(stream)
107
- } catch (e) {
108
- t.equal((e as Error).message, 'no name')
109
- }
110
- })
111
-
112
- test('should handle first error catch', async t => {
113
- t.plan(1)
114
- const FILE_BOX_DATA = 'test'
115
- const FILE_BOX_NAME = 'test.dat'
116
-
117
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, false, true)
118
-
119
- try {
120
- await unpackFileBoxFromChunk(stream)
121
- } catch (e) {
122
- t.equal((e as Error).message, 'first exception')
123
- }
124
- })
125
-
126
- test('should handle middle error in further ops', async t => {
127
- t.plan(1)
128
- const FILE_BOX_DATA = 'test'
129
- const FILE_BOX_NAME = 'test.dat'
130
-
131
- const stream = await getFileBoxStreamStub(FILE_BOX_DATA, FILE_BOX_NAME, false, false, true)
132
-
133
- const fileBox = await unpackFileBoxFromChunk(stream)
134
- try {
135
- await fileBox.toBuffer()
136
- } catch (e) {
137
- t.equal((e as Error).message, 'middle exception')
138
- }
139
- })
140
-
141
- async function getFileBoxStreamStub (
142
- data: string,
143
- name: string,
144
- noname = false,
145
- firstException = false,
146
- middleException = false,
147
- ) {
148
- const fileBox = FileBox.fromBuffer(
149
- Buffer.from(data),
150
- name,
151
- )
152
-
153
- const stream: Duplex<puppet.FileBoxChunk, puppet.FileBoxChunk> = new PassThrough({ objectMode: true })
154
-
155
- if (firstException) {
156
- stream.pause()
157
- setImmediate(() => {
158
- stream.emit('error', new Error('first exception'))
159
- stream.resume()
160
- })
161
- } else {
162
- const chunk1 = new puppet.FileBoxChunk()
163
- if (!noname) {
164
- chunk1.setName(fileBox.name)
165
- }
166
- setTimeout(() => stream.write(chunk1), 10)
167
- }
168
-
169
- if (middleException) {
170
- setTimeout(() => {
171
- stream.emit('error', new Error('middle exception'))
172
- }, 100)
173
- }
174
-
175
- const fileBoxStream = await fileBox.toStream()
176
- fileBoxStream.on('data', chunk => {
177
- const fileBoxChunk = new puppet.FileBoxChunk()
178
- fileBoxChunk.setData(chunk)
179
- setTimeout(() => stream.write(fileBoxChunk), 200)
180
- })
181
- fileBoxStream.on('end', () => setTimeout(() => stream.end(), 250))
182
-
183
- return stream
184
- }
@@ -1,87 +0,0 @@
1
- import { FileBox } from 'file-box'
2
- import type { FileBoxInterface } from 'file-box'
3
- import { PassThrough } from 'stream'
4
- import {
5
- Readable,
6
- Transform,
7
- } from 'stronger-typed-streams'
8
-
9
- import { puppet } from '@juzi/wechaty-grpc'
10
-
11
- import { nextData } from './next-data.js'
12
-
13
- /**
14
- * @deprecated Will be removed after Dec 31, 2022
15
- */
16
- const decoder = () => new Transform<puppet.FileBoxChunk, any>({
17
- objectMode: true,
18
- transform: (chunk: puppet.FileBoxChunk, _: any, callback: any) => {
19
- if (!chunk.hasData()) {
20
- callback(new Error('no data'))
21
- return
22
- }
23
- const data = chunk.getData()
24
- callback(null, data)
25
- },
26
- })
27
-
28
- /**
29
- * @deprecated Will be removed after Dec 31, 2022
30
- */
31
- async function unpackFileBoxFromChunk (
32
- stream: Readable<puppet.FileBoxChunk>,
33
- ): Promise<FileBox> {
34
- const chunk = await nextData(stream)
35
- if (!chunk.hasName()) {
36
- throw new Error('no name')
37
- }
38
- const fileName = chunk.getName()
39
-
40
- const fileStream = new PassThrough({ objectMode: true })
41
- const transformedStream = stream.pipe(decoder())
42
- transformedStream.pipe(fileStream)
43
- stream.on('error', e => fileStream.emit('error', e))
44
- transformedStream.on('error', e => fileStream.emit('error', e))
45
-
46
- const fileBox = FileBox.fromStream(fileStream, fileName)
47
-
48
- return fileBox
49
- }
50
-
51
- /**
52
- * @deprecated Will be removed after Dec 31, 2022
53
- */
54
- const encoder = () => new Transform<any, puppet.FileBoxChunk>({
55
- objectMode: true,
56
- transform: (chunk: any, _: any, callback: any) => {
57
- const fileBoxChunk = new puppet.FileBoxChunk()
58
- fileBoxChunk.setData(chunk)
59
- callback(null, fileBoxChunk)
60
- },
61
- })
62
-
63
- /**
64
- * @deprecated Will be removed after Dec 31, 2022
65
- */
66
- async function packFileBoxToChunk (
67
- fileBox: FileBoxInterface,
68
- ): Promise<Readable<puppet.FileBoxChunk>> {
69
- const stream = new PassThrough({ objectMode: true })
70
-
71
- const chunk = new puppet.FileBoxChunk()
72
- chunk.setName(fileBox.name)
73
-
74
- // FIXME: Huan(202010) write might return false
75
- stream.write(chunk)
76
-
77
- fileBox
78
- .pipe(encoder())
79
- .pipe(stream)
80
-
81
- return stream
82
- }
83
-
84
- export {
85
- unpackFileBoxFromChunk,
86
- packFileBoxToChunk,
87
- }
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2
-
3
- import { test } from 'tstest'
4
-
5
- import { FileBox } from 'file-box'
6
-
7
- import {
8
- puppet,
9
- } from '@juzi/wechaty-grpc'
10
-
11
- import {
12
- packFileBoxToPb,
13
- unpackFileBoxFromPb,
14
- } from './file-box-pb.js'
15
-
16
- test('packFileBoxToPb()', async t => {
17
- const FILE_BOX_DATA = 'test'
18
- const FILE_BOX_NAME = 'test.dat'
19
-
20
- const fileBox = FileBox.fromBuffer(
21
- Buffer.from(FILE_BOX_DATA),
22
- FILE_BOX_NAME,
23
- )
24
-
25
- const pb = await packFileBoxToPb(puppet.MessageFileStreamResponse)(fileBox)
26
- const restoredFileBox = await unpackFileBoxFromPb(pb)
27
- t.ok(restoredFileBox instanceof FileBox, 'should get an instance of FileBOX')
28
-
29
- t.equal(restoredFileBox.name, fileBox.name, 'should get the right file box name')
30
- t.equal(await restoredFileBox.toBase64(), await fileBox.toBase64(), 'should get the right file box content')
31
- })
@@ -1,41 +0,0 @@
1
- import type { FileBoxInterface } from 'file-box'
2
- import type { Readable } from 'stronger-typed-streams'
3
-
4
- import {
5
- packFileBoxToChunk,
6
- unpackFileBoxFromChunk,
7
- } from './file-box-chunk.js'
8
- import {
9
- packFileBoxChunkToPb,
10
- unpackFileBoxChunkFromPb,
11
- } from './chunk-pb.js'
12
- import type { FileBoxPb } from './file-box-pb.type.js'
13
-
14
- /**
15
- * @deprecated Will be removed after Dec 31, 2022
16
- */
17
- function packFileBoxToPb<T extends FileBoxPb> (
18
- PbConstructor: { new(): T },
19
- ) {
20
- return async (fileBox: FileBoxInterface) => {
21
- const fileBoxChunkStream = await packFileBoxToChunk(fileBox)
22
- const pbFileBox = packFileBoxChunkToPb(PbConstructor)(fileBoxChunkStream)
23
- return pbFileBox
24
- }
25
- }
26
-
27
- /**
28
- * @deprecated Will be removed after Dec 31, 2022
29
- */
30
- async function unpackFileBoxFromPb<T extends FileBoxPb> (
31
- pbStream: Readable<T>,
32
- ): Promise<FileBoxInterface> {
33
- const fileBoxChunkStream = unpackFileBoxChunkFromPb(pbStream)
34
- const fileBox = await unpackFileBoxFromChunk(fileBoxChunkStream)
35
- return fileBox
36
- }
37
-
38
- export {
39
- packFileBoxToPb,
40
- unpackFileBoxFromPb,
41
- }
@@ -1,16 +0,0 @@
1
- import type { puppet } from '@juzi/wechaty-grpc'
2
-
3
- /**
4
- * Any Protocol Buffer message that include a FileBoxChunk
5
- */
6
- export interface FileBoxPb {
7
- hasFileBoxChunk(): boolean
8
- getFileBoxChunk(): puppet.FileBoxChunk | undefined
9
- setFileBoxChunk(value?: puppet.FileBoxChunk): void
10
- }
11
-
12
- export interface ConversationIdFileBoxPb extends FileBoxPb {
13
- hasConversationId(): boolean
14
- getConversationId(): string
15
- setConversationId(value: string): void
16
- }
@@ -1,8 +0,0 @@
1
- export {
2
- packConversationIdFileBoxToPb,
3
- unpackConversationIdFileBoxArgsFromPb,
4
- } from './conversation-id-file-box.js'
5
- export {
6
- packFileBoxToPb,
7
- unpackFileBoxFromPb,
8
- } from './file-box-pb.js'
@@ -1,35 +0,0 @@
1
- import type {
2
- Readable,
3
- } from 'stronger-typed-streams'
4
-
5
- /**
6
- * windmemory(20201027): generating fileBox data in server side might take longer.
7
- * Set to 60 sec to avoid unexpected timeout.
8
- */
9
- const TIMEOUT = 60 * 1000
10
-
11
- /**
12
- * @deprecated Will be removed after Dec 31, 2022
13
- */
14
- async function nextData<T> (
15
- stream: Readable<T>,
16
- ): Promise<T> {
17
- const chunk = await new Promise<T>((resolve, reject) => {
18
- const timer = setTimeout(reject, TIMEOUT)
19
- stream.once('data', chunk => {
20
- stream.pause()
21
- clearTimeout(timer)
22
-
23
- resolve(chunk)
24
- })
25
- stream.once('error', reject)
26
-
27
- })
28
-
29
- stream.resume()
30
- return chunk
31
- }
32
-
33
- export {
34
- nextData,
35
- }
@@ -1,24 +0,0 @@
1
- import {
2
- FileBox,
3
- FileBoxType,
4
- } from 'file-box'
5
- import type {
6
- FileBoxInterface,
7
- } from 'file-box'
8
-
9
- /**
10
- * @deprecated Will be removed after Dec 31, 2022
11
- */
12
- export const serializeFileBox = async (fileBox: FileBoxInterface): Promise<string> => {
13
- const serializableFileBoxTypes = [
14
- FileBoxType.Base64,
15
- FileBoxType.Url,
16
- FileBoxType.QRCode,
17
- ]
18
- if (serializableFileBoxTypes.includes(fileBox.type)) {
19
- return JSON.stringify(fileBox)
20
- }
21
- const base64 = await fileBox.toBase64()
22
- const name = fileBox.name
23
- return JSON.stringify(FileBox.fromBase64(base64, name))
24
- }