@juzi/wechaty-puppet-service 1.0.43 → 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 +0 -4
- package/dist/cjs/src/client/puppet-service.d.ts.map +1 -1
- package/dist/cjs/src/client/puppet-service.js +39 -129
- package/dist/cjs/src/client/puppet-service.js.map +1 -1
- package/dist/cjs/src/package-json.js +2 -2
- package/dist/cjs/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/cjs/src/server/puppet-implementation.js +2 -66
- package/dist/cjs/src/server/puppet-implementation.js.map +1 -1
- package/dist/esm/src/client/puppet-service.d.ts +0 -4
- package/dist/esm/src/client/puppet-service.d.ts.map +1 -1
- package/dist/esm/src/client/puppet-service.js +36 -126
- package/dist/esm/src/client/puppet-service.js.map +1 -1
- package/dist/esm/src/package-json.js +2 -2
- package/dist/esm/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/esm/src/server/puppet-implementation.js +0 -64
- package/dist/esm/src/server/puppet-implementation.js.map +1 -1
- package/package.json +2 -2
- package/src/client/puppet-service.ts +41 -148
- package/src/package-json.ts +2 -2
- package/src/server/puppet-implementation.ts +0 -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
|
@@ -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
|
-
}
|
package/src/deprecated/mod.ts
DELETED
|
@@ -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
|
-
}
|