@openclaw/whatsapp 2026.7.2-beta.7 → 2026.7.34
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/README.md +1 -1
- package/dist/{access-control-pZcxTmd5.js → .setup/access-control-C0jumQuO.mjs} +5 -4
- package/dist/.setup/account-config-6PTOSfaI.mjs +47 -0
- package/dist/{accounts-CSqLvCY5.js → .setup/accounts-Dw16pdNl.mjs} +9 -47
- package/dist/{action-runtime-BzfDFPbH.js → .setup/action-runtime-DLK_9v4r.mjs} +3 -3
- package/dist/{active-listener-BEjWsCNM.js → .setup/active-listener-CloPBx0S.mjs} +3 -3
- package/dist/{agent-tools-login-DE9MU98T.js → .setup/agent-tools-login-DINqgaYo.mjs} +19 -7
- package/dist/{approval-handler.runtime-DrA59QSA.js → .setup/approval-handler.runtime-DtJZbu3y.mjs} +14 -20
- package/dist/{approval-resolver-DoeBBt22.js → .setup/approval-resolver-DF-lu8k5.mjs} +1 -2
- package/dist/{auth-store-DcEpIOmE.js → .setup/auth-store-BZKGa0tW.mjs} +25 -29
- package/dist/{channel-Dg62olhy.js → .setup/channel-9WGjBznd.mjs} +117 -132
- package/dist/{channel-react-action-J_YtyMGX.js → .setup/channel-react-action-mvIbAFhn.mjs} +15 -12
- package/dist/{channel.runtime-BP0xNmLi.js → .setup/channel.runtime-DmmMgRJQ.mjs} +6 -6
- package/dist/.setup/channel.setup-ByBYSeLd.mjs +22 -0
- package/dist/.setup/config-schema-mBX2nmn1.mjs +47 -0
- package/dist/{connection-controller-BOB2MVKY.js → .setup/connection-controller-Dt62u6fI.mjs} +29 -226
- package/dist/.setup/connection-controller-registry-TSX_udJp.mjs +22 -0
- package/dist/{constants-HU41RHGI.js → .setup/constants-C7m81BNe.mjs} +1 -1
- package/dist/.setup/directory-config-B7Obxrq2.mjs +37 -0
- package/dist/.setup/doctor-By3SB4lm.mjs +48 -0
- package/dist/{group-session-key-DVMZlO3x.js → .setup/group-session-key-CEwPRRRK.mjs} +5 -38
- package/dist/{identity-CPrT5aEU.js → .setup/identity-CDB1bT-p.mjs} +2 -2
- package/dist/.setup/legacy-session-surface-api-B2szjq4r.mjs +2 -0
- package/dist/.setup/legacy-state-migrations-api-DXCxufZz.mjs +3 -0
- package/dist/{login-CvY2Dhch.js → .setup/login-7b3M0iBp.mjs} +12 -51
- package/dist/{login-qr-Bncpb6js.js → .setup/login-qr-CbyA4QX5.mjs} +47 -23
- package/dist/{monitor-CfkaUSL2.js → .setup/monitor-Dh6Di_YO.mjs} +1451 -1843
- package/dist/.setup/normalize-eddWWsNV.mjs +2 -0
- package/dist/{normalize-target-CugRyONv.js → .setup/normalize-target-bVWjgftN.mjs} +10 -18
- package/dist/{resolve-outbound-target-1GqbT1uX.js → .setup/resolve-outbound-target-oI7VpU4w.mjs} +1 -1
- package/dist/.setup/runtime-BfAdAEYT.mjs +8 -0
- package/dist/.setup/send-BQjMC41n.mjs +777 -0
- package/dist/{send-api-7wk6eQyW.js → .setup/send-api-BiAkPLr3.mjs} +155 -105
- package/dist/{session-errors-JuazczrA.js → .setup/session-errors-BAj9D2La.mjs} +1 -2
- package/dist/.setup/session-vUI41Jel.mjs +252 -0
- package/dist/.setup/session.runtime-B-V3rXP6.mjs +12 -0
- package/dist/{shared-CAxd15bp.js → .setup/setup-core--FfzntMG.mjs} +94 -63
- package/dist/{setup-finalize-BZucx24W.js → .setup/setup-finalize-DCruIciL.mjs} +17 -46
- package/dist/.setup/setup-plugin-api-B6ck_20D.mjs +3 -0
- package/dist/{setup-surface-BkVcd769.js → .setup/setup-surface-Zvj2cLzz.mjs} +4 -4
- package/dist/.setup/socket-timing-DhbVFjah.mjs +77 -0
- package/dist/{state-migrations-CAMTrs2U.js → .setup/state-migrations-D_BmQUR9.mjs} +8 -1
- package/dist/.setup/targets-runtime-C-GiVn6Y.mjs +188 -0
- package/dist/.setup/text-runtime-CUrq1mFq.mjs +4 -0
- package/dist/action-runtime-api.js +1 -1
- package/dist/action-runtime.runtime.js +1 -1
- package/dist/{call-tool-api.js → agent-tools-api.js} +26 -11
- package/dist/api.js +27 -17
- package/dist/auth-presence.js +1 -1
- package/dist/channel-config-api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +5 -5
- package/dist/directory-contract-api.js +1 -1
- package/dist/doctor-contract-api.js +5 -46
- package/dist/index.js +4 -4
- package/dist/legacy-session-surface-api.js +1 -1
- package/dist/legacy-state-migrations-api.js +1 -1
- package/dist/light-runtime-api.js +4 -4
- package/dist/login-qr-runtime.js +1 -1
- package/dist/runtime-api.js +14 -14
- package/dist/runtime-setter-api.js +1 -1
- package/dist/security-contract-api.js +1 -1
- package/dist/setup-entry.js +4 -3
- package/dist/setup-plugin-api.js +1 -1
- package/dist/targets.js +2 -0
- package/node_modules/audio-decode/node_modules/@thi.ng/bitstream/package.json +4 -4
- package/node_modules/audio-decode/node_modules/@thi.ng/errors/package.json +4 -4
- package/node_modules/audio-decode/node_modules/audio-type/package.json +2 -3
- package/node_modules/baileys/node_modules/@protobufjs/aspromise/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/aspromise/README.md +13 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/aspromise.d.ts → @protobufjs/aspromise/index.d.ts} +13 -13
- package/node_modules/baileys/node_modules/{protobufjs/src/util/aspromise.js → @protobufjs/aspromise/index.js} +52 -52
- package/node_modules/baileys/node_modules/@protobufjs/aspromise/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/aspromise/tests/index.js +130 -0
- package/node_modules/baileys/node_modules/@protobufjs/base64/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/base64/README.md +19 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/base64.d.ts → @protobufjs/base64/index.d.ts} +32 -32
- package/node_modules/baileys/node_modules/{protobufjs/src/util/base64.js → @protobufjs/base64/index.js} +139 -146
- package/node_modules/baileys/node_modules/@protobufjs/base64/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/base64/tests/index.js +46 -0
- package/node_modules/baileys/node_modules/@protobufjs/codegen/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/codegen/README.md +49 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/codegen.d.ts → @protobufjs/codegen/index.d.ts} +31 -31
- package/node_modules/baileys/node_modules/{protobufjs/src/util/codegen.js → @protobufjs/codegen/index.js} +112 -118
- package/node_modules/baileys/node_modules/@protobufjs/codegen/package.json +13 -0
- package/node_modules/baileys/node_modules/@protobufjs/codegen/tests/index.js +13 -0
- package/node_modules/baileys/node_modules/@protobufjs/eventemitter/CHANGELOG.md +8 -0
- package/node_modules/baileys/node_modules/@protobufjs/eventemitter/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/eventemitter/README.md +22 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/eventemitter.d.ts → @protobufjs/eventemitter/index.d.ts} +45 -45
- package/node_modules/baileys/node_modules/{protobufjs/src/util/eventemitter.js → @protobufjs/eventemitter/index.js} +86 -86
- package/node_modules/baileys/node_modules/@protobufjs/eventemitter/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/eventemitter/tests/index.js +83 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/CHANGELOG.md +8 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/README.md +13 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/fetch.d.ts → @protobufjs/fetch/index.d.ts} +56 -56
- package/node_modules/baileys/node_modules/{protobufjs/src/util/fetch.js → @protobufjs/fetch/index.js} +112 -112
- package/node_modules/baileys/node_modules/@protobufjs/fetch/package.json +27 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/tests/data/file.txt +1 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/tests/index.js +158 -0
- package/node_modules/baileys/node_modules/@protobufjs/fetch/util/fs.js +11 -0
- package/node_modules/baileys/node_modules/@protobufjs/float/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/float/README.md +102 -0
- package/node_modules/baileys/node_modules/@protobufjs/float/bench/index.js +87 -0
- package/node_modules/baileys/node_modules/@protobufjs/float/bench/suite.js +46 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/float.js → @protobufjs/float/index.js} +335 -335
- package/node_modules/baileys/node_modules/@protobufjs/float/package.json +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/float/tests/index.js +100 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/CHANGELOG.md +8 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/README.md +13 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/index.d.ts +10 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/index.js +38 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/tests/data/array.js +1 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/tests/data/emptyArray.js +1 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/tests/data/emptyObject.js +1 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/tests/data/object.js +1 -0
- package/node_modules/baileys/node_modules/@protobufjs/inquire/tests/index.js +20 -0
- package/node_modules/baileys/node_modules/@protobufjs/path/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/path/README.md +19 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/path.d.ts → @protobufjs/path/index.d.ts} +22 -22
- package/node_modules/baileys/node_modules/{protobufjs/src/util/path.js → @protobufjs/path/index.js} +65 -100
- package/node_modules/baileys/node_modules/@protobufjs/path/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/path/tests/index.js +60 -0
- package/node_modules/baileys/node_modules/@protobufjs/pool/.npmignore +3 -0
- package/node_modules/baileys/node_modules/@protobufjs/pool/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/pool/README.md +13 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/pool.d.ts → @protobufjs/pool/index.d.ts} +32 -32
- package/node_modules/baileys/node_modules/{protobufjs/src/util/pool.js → @protobufjs/pool/index.js} +48 -48
- package/node_modules/baileys/node_modules/@protobufjs/pool/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/pool/tests/index.js +33 -0
- package/node_modules/baileys/node_modules/@protobufjs/utf8/LICENSE +26 -0
- package/node_modules/baileys/node_modules/@protobufjs/utf8/README.md +20 -0
- package/node_modules/baileys/node_modules/{protobufjs/src/util/utf8.d.ts → @protobufjs/utf8/index.d.ts} +24 -24
- package/node_modules/baileys/node_modules/{protobufjs/src/util/utf8.js → @protobufjs/utf8/index.js} +104 -190
- package/node_modules/baileys/node_modules/@protobufjs/utf8/package.json +21 -0
- package/node_modules/baileys/node_modules/@protobufjs/utf8/tests/data/surrogate_pair_bug.txt +207 -0
- package/node_modules/baileys/node_modules/@protobufjs/utf8/tests/data/utf8.txt +216 -0
- package/node_modules/baileys/node_modules/@protobufjs/utf8/tests/index.js +74 -0
- package/node_modules/baileys/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/baileys/node_modules/@types/node/README.md +15 -0
- package/node_modules/baileys/node_modules/@types/node/assert/strict.d.ts +68 -0
- package/node_modules/baileys/node_modules/@types/node/assert.d.ts +1077 -0
- package/node_modules/baileys/node_modules/@types/node/async_hooks.d.ts +711 -0
- package/node_modules/baileys/node_modules/@types/node/buffer.buffer.d.ts +466 -0
- package/node_modules/baileys/node_modules/@types/node/buffer.d.ts +1799 -0
- package/node_modules/baileys/node_modules/@types/node/child_process.d.ts +1362 -0
- package/node_modules/baileys/node_modules/@types/node/cluster.d.ts +432 -0
- package/node_modules/baileys/node_modules/@types/node/console.d.ts +93 -0
- package/node_modules/baileys/node_modules/@types/node/constants.d.ts +14 -0
- package/node_modules/baileys/node_modules/@types/node/crypto.d.ts +3954 -0
- package/node_modules/baileys/node_modules/@types/node/dgram.d.ts +537 -0
- package/node_modules/baileys/node_modules/@types/node/diagnostics_channel.d.ts +794 -0
- package/node_modules/baileys/node_modules/@types/node/dns/promises.d.ts +497 -0
- package/node_modules/baileys/node_modules/@types/node/dns.d.ts +876 -0
- package/node_modules/baileys/node_modules/@types/node/domain.d.ts +150 -0
- package/node_modules/baileys/node_modules/@types/node/events.d.ts +1008 -0
- package/node_modules/baileys/node_modules/@types/node/ffi.d.ts +486 -0
- package/node_modules/baileys/node_modules/@types/node/fs/promises.d.ts +1471 -0
- package/node_modules/baileys/node_modules/@types/node/fs.d.ts +4786 -0
- package/node_modules/baileys/node_modules/@types/node/globals.d.ts +150 -0
- package/node_modules/baileys/node_modules/@types/node/globals.typedarray.d.ts +101 -0
- package/node_modules/baileys/node_modules/@types/node/http.d.ts +2172 -0
- package/node_modules/baileys/node_modules/@types/node/http2.d.ts +2489 -0
- package/node_modules/baileys/node_modules/@types/node/https.d.ts +400 -0
- package/node_modules/baileys/node_modules/@types/node/index.d.ts +115 -0
- package/node_modules/baileys/node_modules/@types/node/inspector/promises.d.ts +35 -0
- package/node_modules/baileys/node_modules/@types/node/inspector.d.ts +264 -0
- package/node_modules/baileys/node_modules/@types/node/inspector.generated.d.ts +4406 -0
- package/node_modules/baileys/node_modules/@types/node/module.d.ts +726 -0
- package/node_modules/baileys/node_modules/@types/node/net.d.ts +970 -0
- package/node_modules/baileys/node_modules/@types/node/os.d.ts +498 -0
- package/node_modules/baileys/node_modules/@types/node/package.json +155 -0
- package/node_modules/baileys/node_modules/@types/node/path/posix.d.ts +8 -0
- package/node_modules/baileys/node_modules/@types/node/path/win32.d.ts +8 -0
- package/node_modules/baileys/node_modules/@types/node/path.d.ts +178 -0
- package/node_modules/baileys/node_modules/@types/node/perf_hooks.d.ts +604 -0
- package/node_modules/baileys/node_modules/@types/node/process.d.ts +2217 -0
- package/node_modules/baileys/node_modules/@types/node/punycode.d.ts +89 -0
- package/node_modules/baileys/node_modules/@types/node/querystring.d.ts +139 -0
- package/node_modules/baileys/node_modules/@types/node/quic.d.ts +978 -0
- package/node_modules/baileys/node_modules/@types/node/readline/promises.d.ts +158 -0
- package/node_modules/baileys/node_modules/@types/node/readline.d.ts +508 -0
- package/node_modules/baileys/node_modules/@types/node/repl.d.ts +420 -0
- package/node_modules/baileys/node_modules/@types/node/sea.d.ts +47 -0
- package/node_modules/baileys/node_modules/@types/node/sqlite.d.ts +1123 -0
- package/node_modules/baileys/node_modules/@types/node/stream/consumers.d.ts +114 -0
- package/node_modules/baileys/node_modules/@types/node/stream/iter.d.ts +451 -0
- package/node_modules/baileys/node_modules/@types/node/stream/promises.d.ts +211 -0
- package/node_modules/baileys/node_modules/@types/node/stream/web.d.ts +300 -0
- package/node_modules/baileys/node_modules/@types/node/stream.d.ts +1806 -0
- package/node_modules/baileys/node_modules/@types/node/string_decoder.d.ts +27 -0
- package/node_modules/baileys/node_modules/@types/node/test/reporters.d.ts +59 -0
- package/node_modules/baileys/node_modules/@types/node/test.d.ts +2389 -0
- package/node_modules/baileys/node_modules/@types/node/timers/promises.d.ts +93 -0
- package/node_modules/baileys/node_modules/@types/node/timers.d.ts +149 -0
- package/node_modules/baileys/node_modules/@types/node/tls.d.ts +1193 -0
- package/node_modules/baileys/node_modules/@types/node/trace_events.d.ts +103 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +462 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.6/index.d.ts +117 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/baileys/node_modules/@types/node/ts5.7/index.d.ts +117 -0
- package/node_modules/baileys/node_modules/@types/node/tty.d.ts +225 -0
- package/node_modules/baileys/node_modules/@types/node/url.d.ts +556 -0
- package/node_modules/baileys/node_modules/@types/node/util/types.d.ts +558 -0
- package/node_modules/baileys/node_modules/@types/node/util.d.ts +1677 -0
- package/node_modules/baileys/node_modules/@types/node/v8.d.ts +1062 -0
- package/node_modules/baileys/node_modules/@types/node/vm.d.ts +1136 -0
- package/node_modules/baileys/node_modules/@types/node/wasi.d.ts +131 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/abortcontroller.d.ts +59 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/blob.d.ts +23 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/console.d.ts +9 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/domexception.d.ts +83 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/events.d.ts +106 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/fetch.d.ts +69 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/performance.d.ts +45 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/streams.d.ts +115 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/timers.d.ts +44 -0
- package/node_modules/baileys/node_modules/@types/node/web-globals/url.d.ts +24 -0
- package/node_modules/baileys/node_modules/@types/node/worker_threads.d.ts +669 -0
- package/node_modules/baileys/node_modules/@types/node/zlib/iter.d.ts +131 -0
- package/node_modules/baileys/node_modules/@types/node/zlib.d.ts +589 -0
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/browser/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/browser/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/browser/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/browser/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/node/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/node/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/node/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/node/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/commonjs/node/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/browser/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/browser/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/browser/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/browser/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/browser/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/node/index.d.ts.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/node/index.js +4 -11
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/node/index.js.map +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/node/index.min.js +1 -1
- package/node_modules/baileys/node_modules/lru-cache/dist/esm/node/index.min.js.map +3 -3
- package/node_modules/baileys/node_modules/lru-cache/package.json +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/common/Util.d.ts +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/common/Util.js +1 -7
- package/node_modules/baileys/node_modules/music-metadata/lib/id3v2/FrameHeader.js +3 -23
- package/node_modules/baileys/node_modules/music-metadata/lib/id3v2/FrameParser.js +2 -2
- package/node_modules/baileys/node_modules/music-metadata/lib/id3v2/ID3v2Token.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/mp4/AtomToken.js +13 -38
- package/node_modules/baileys/node_modules/music-metadata/lib/mpeg/MpegParser.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/package.json +6 -6
- package/node_modules/baileys/node_modules/p-queue/dist/index.js +27 -37
- package/node_modules/baileys/node_modules/p-queue/package.json +1 -1
- package/node_modules/baileys/node_modules/protobufjs/README.md +553 -266
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js +1985 -3177
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js +1244 -1966
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js +2005 -3330
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor/README.md +70 -3
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor/index.d.ts +193 -0
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor/index.js +1185 -1
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor/test.js +54 -0
- package/node_modules/baileys/node_modules/protobufjs/google/api/annotations.json +1 -3
- package/node_modules/baileys/node_modules/protobufjs/google/api/http.json +1 -2
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/api.json +6 -12
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/descriptor.json +87 -170
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/descriptor.proto +8 -0
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/source_context.json +1 -2
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/type.json +7 -14
- package/node_modules/baileys/node_modules/protobufjs/index.d.ts +703 -1066
- package/node_modules/baileys/node_modules/protobufjs/package.json +52 -25
- package/node_modules/baileys/node_modules/protobufjs/scripts/postinstall.js +32 -0
- package/node_modules/baileys/node_modules/protobufjs/src/common.js +8 -14
- package/node_modules/baileys/node_modules/protobufjs/src/converter.js +51 -85
- package/node_modules/baileys/node_modules/protobufjs/src/decoder.js +61 -205
- package/node_modules/baileys/node_modules/protobufjs/src/encoder.js +7 -27
- package/node_modules/baileys/node_modules/protobufjs/src/enum.js +5 -18
- package/node_modules/baileys/node_modules/protobufjs/src/field.js +19 -71
- package/node_modules/baileys/node_modules/protobufjs/src/index-light.js +29 -29
- package/node_modules/baileys/node_modules/protobufjs/src/index-minimal.js +13 -12
- package/node_modules/baileys/node_modules/protobufjs/src/index.js +6 -6
- package/node_modules/baileys/node_modules/protobufjs/src/mapfield.js +8 -26
- package/node_modules/baileys/node_modules/protobufjs/src/message.js +11 -5
- package/node_modules/baileys/node_modules/protobufjs/src/method.js +7 -30
- package/node_modules/baileys/node_modules/protobufjs/src/namespace.js +10 -26
- package/node_modules/baileys/node_modules/protobufjs/src/object.js +31 -41
- package/node_modules/baileys/node_modules/protobufjs/src/oneof.js +1 -12
- package/node_modules/baileys/node_modules/protobufjs/src/parse.js +47 -169
- package/node_modules/baileys/node_modules/protobufjs/src/reader.js +50 -412
- package/node_modules/baileys/node_modules/protobufjs/src/reader_buffer.js +5 -31
- package/node_modules/baileys/node_modules/protobufjs/src/root.js +4 -16
- package/node_modules/baileys/node_modules/protobufjs/src/rpc/service.js +5 -18
- package/node_modules/baileys/node_modules/protobufjs/src/service.js +2 -15
- package/node_modules/baileys/node_modules/protobufjs/src/tokenize.js +1 -6
- package/node_modules/baileys/node_modules/protobufjs/src/type.js +36 -80
- package/node_modules/baileys/node_modules/protobufjs/src/typescript.jsdoc +15 -0
- package/node_modules/baileys/node_modules/protobufjs/src/util/longbits.js +6 -10
- package/node_modules/baileys/node_modules/protobufjs/src/util/minimal.js +54 -71
- package/node_modules/baileys/node_modules/protobufjs/src/util.js +17 -51
- package/node_modules/baileys/node_modules/protobufjs/src/verifier.js +14 -19
- package/node_modules/baileys/node_modules/protobufjs/src/wrappers.js +3 -2
- package/node_modules/baileys/node_modules/protobufjs/src/writer.js +191 -424
- package/node_modules/baileys/node_modules/protobufjs/src/writer_buffer.js +26 -41
- package/node_modules/baileys/node_modules/protobufjs/tsconfig.json +5 -3
- package/node_modules/baileys/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/baileys/node_modules/undici-types/README.md +6 -0
- package/node_modules/baileys/node_modules/undici-types/agent.d.ts +30 -0
- package/node_modules/baileys/node_modules/undici-types/api.d.ts +43 -0
- package/node_modules/baileys/node_modules/undici-types/balanced-pool.d.ts +30 -0
- package/node_modules/baileys/node_modules/undici-types/cache-interceptor.d.ts +179 -0
- package/node_modules/baileys/node_modules/undici-types/cache.d.ts +36 -0
- package/node_modules/baileys/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/baileys/node_modules/undici-types/client.d.ts +129 -0
- package/node_modules/baileys/node_modules/undici-types/connector.d.ts +36 -0
- package/node_modules/baileys/node_modules/undici-types/content-type.d.ts +21 -0
- package/node_modules/baileys/node_modules/undici-types/cookies.d.ts +30 -0
- package/node_modules/baileys/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
- package/node_modules/baileys/node_modules/undici-types/dispatcher.d.ts +253 -0
- package/node_modules/baileys/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
- package/node_modules/baileys/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/baileys/node_modules/undici-types/errors.d.ts +177 -0
- package/node_modules/baileys/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/baileys/node_modules/undici-types/fetch.d.ts +231 -0
- package/node_modules/baileys/node_modules/undici-types/formdata.d.ts +108 -0
- package/node_modules/baileys/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/node_modules/baileys/node_modules/undici-types/global-origin.d.ts +7 -0
- package/node_modules/baileys/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/baileys/node_modules/undici-types/handlers.d.ts +14 -0
- package/node_modules/baileys/node_modules/undici-types/header.d.ts +165 -0
- package/node_modules/baileys/node_modules/undici-types/index.d.ts +93 -0
- package/node_modules/baileys/node_modules/undici-types/interceptors.d.ts +80 -0
- package/node_modules/baileys/node_modules/undici-types/mock-agent.d.ts +68 -0
- package/node_modules/baileys/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/baileys/node_modules/undici-types/mock-client.d.ts +27 -0
- package/node_modules/baileys/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/node_modules/baileys/node_modules/undici-types/mock-interceptor.d.ts +94 -0
- package/node_modules/baileys/node_modules/undici-types/mock-pool.d.ts +27 -0
- package/node_modules/baileys/node_modules/undici-types/package.json +55 -0
- package/node_modules/baileys/node_modules/undici-types/patch.d.ts +29 -0
- package/node_modules/baileys/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/node_modules/baileys/node_modules/undici-types/pool.d.ts +39 -0
- package/node_modules/baileys/node_modules/undici-types/proxy-agent.d.ts +29 -0
- package/node_modules/baileys/node_modules/undici-types/readable.d.ts +68 -0
- package/node_modules/baileys/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/baileys/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/baileys/node_modules/undici-types/round-robin-pool.d.ts +39 -0
- package/node_modules/baileys/node_modules/undici-types/snapshot-agent.d.ts +113 -0
- package/node_modules/baileys/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/baileys/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/baileys/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/baileys/node_modules/undici-types/webidl.d.ts +346 -0
- package/node_modules/baileys/node_modules/undici-types/websocket.d.ts +188 -0
- package/node_modules/baileys/node_modules/ws/lib/permessage-deflate.js +3 -1
- package/node_modules/baileys/node_modules/ws/package.json +1 -1
- package/node_modules/typebox/build/compile/validator.d.mts +4 -1
- package/node_modules/typebox/build/guard/guard.d.mts +1 -1
- package/node_modules/typebox/build/guard/guard.mjs +2 -5
- package/node_modules/typebox/build/guard/string.mjs +4 -16
- package/node_modules/typebox/build/schema/engine/_functions.mjs +15 -34
- package/node_modules/typebox/build/type/action/readonly_object.d.mts +0 -5
- package/node_modules/typebox/build/type/action/readonly_object.mjs +0 -8
- package/node_modules/typebox/build/typebox.d.mts +1 -1
- package/node_modules/typebox/build/typebox.mjs +1 -1
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +32 -29
- package/openclaw.plugin.json +239 -214
- package/package.json +11 -21
- package/dist/approval-reactions-Cu66aYdq.js +0 -373
- package/dist/channel.setup-pMwNVkCA.js +0 -19
- package/dist/config-schema-BQP5YCeK.js +0 -50
- package/dist/connection-controller-runtime-context-DG0tuYuw.js +0 -23
- package/dist/directory-config-DalGrfGN.js +0 -196
- package/dist/doctor-CwzVXKoE.js +0 -10
- package/dist/normalize-C7Hkc_vE.js +0 -2
- package/dist/question-reactions-CRsnyoMK.js +0 -142
- package/dist/runtime-BLlToOi6.js +0 -21
- package/dist/send-D37ddk22.js +0 -436
- package/dist/session.runtime-Nsqaehbd.js +0 -16
- package/dist/socket-close-DridEuzz.js +0 -622
- package/dist/targets-runtime-TMk0lGuy.js +0 -299
- package/dist/text-runtime-CaKLhowd.js +0 -4
- package/node_modules/baileys/node_modules/protobufjs/ext/README.md +0 -70
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor.d.ts +0 -87
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor.generated.d.ts +0 -417
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor.js +0 -1356
- package/node_modules/baileys/node_modules/protobufjs/ext/protojson.LICENSE +0 -201
- package/node_modules/baileys/node_modules/protobufjs/ext/protojson.d.ts +0 -20
- package/node_modules/baileys/node_modules/protobufjs/ext/protojson.generated.d.ts +0 -49
- package/node_modules/baileys/node_modules/protobufjs/ext/protojson.js +0 -951
- package/node_modules/baileys/node_modules/protobufjs/ext/textformat.d.ts +0 -19
- package/node_modules/baileys/node_modules/protobufjs/ext/textformat.generated.d.ts +0 -33
- package/node_modules/baileys/node_modules/protobufjs/ext/textformat.js +0 -1276
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/compiler/plugin.json +0 -126
- package/node_modules/baileys/node_modules/protobufjs/google/protobuf/compiler/plugin.proto +0 -47
- package/node_modules/baileys/node_modules/protobufjs/src/typescript.js +0 -25
- /package/dist/{account-ids-CB5SOWjc.js → .setup/account-ids-CB5SOWjc.mjs} +0 -0
- /package/dist/{audio-preflight.runtime-C_glQhZY.js → .setup/audio-preflight.runtime-C_glQhZY.mjs} +0 -0
- /package/dist/{command-policy-BIOSHySD.js → .setup/command-policy-BIOSHySD.mjs} +0 -0
- /package/dist/{creds-files-B1kSWtBg.js → .setup/creds-files-B1kSWtBg.mjs} +0 -0
- /package/dist/{group-config-path-BGyzT9Lg.js → .setup/group-config-path-BGyzT9Lg.mjs} +0 -0
- /package/dist/{group-session-contract-DDnZSsJ1.js → .setup/group-session-contract-DDnZSsJ1.mjs} +0 -0
- /package/dist/{reply-resolver.runtime-Ded8D58Y.js → .setup/reply-resolver.runtime-Ded8D58Y.mjs} +0 -0
- /package/dist/{rolldown-runtime-D7D4PA-g.js → .setup/rolldown-runtime-D7D4PA-g.mjs} +0 -0
- /package/dist/{security-contract-nAzD945y.js → .setup/security-contract-nAzD945y.mjs} +0 -0
- /package/dist/{session-contract-DMTm6Q_L.js → .setup/session-contract-DMTm6Q_L.mjs} +0 -0
- /package/node_modules/baileys/node_modules/{protobufjs/src/util/float.d.ts → @protobufjs/float/index.d.ts} +0 -0
|
@@ -9,432 +9,719 @@
|
|
|
9
9
|
|
|
10
10
|
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://protobuf.dev/)).
|
|
11
11
|
|
|
12
|
-
**protobuf.js** is a
|
|
12
|
+
**protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [Node.js](https://nodejs.org) and the browser. It's easy to use, does not sacrifice on performance, has good conformance and works out of the box with [.proto](https://protobuf.dev/programming-guides/proto3/) files!
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Contents
|
|
15
|
+
--------
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
* [Installation](#installation)<br />
|
|
18
|
+
How to include protobuf.js in your project.
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
* [Usage](#usage)<br />
|
|
21
|
+
A brief introduction to using the toolset.
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
* [Valid Message](#valid-message)
|
|
24
|
+
* [Toolset](#toolset)<br />
|
|
25
|
+
|
|
26
|
+
* [Examples](#examples)<br />
|
|
27
|
+
A few examples to get you started.
|
|
28
|
+
|
|
29
|
+
* [Using .proto files](#using-proto-files)
|
|
30
|
+
* [Using JSON descriptors](#using-json-descriptors)
|
|
31
|
+
* [Using reflection only](#using-reflection-only)
|
|
32
|
+
* [Using custom classes](#using-custom-classes)
|
|
33
|
+
* [Using services](#using-services)
|
|
34
|
+
* [Usage with TypeScript](#usage-with-typescript)<br />
|
|
35
|
+
|
|
36
|
+
* [Additional documentation](#additional-documentation)<br />
|
|
37
|
+
A list of available documentation resources.
|
|
38
|
+
|
|
39
|
+
* [Performance](#performance)<br />
|
|
40
|
+
A few internals and a benchmark on performance.
|
|
41
|
+
|
|
42
|
+
* [Compatibility](#compatibility)<br />
|
|
43
|
+
Notes on compatibility regarding browsers and optional libraries.
|
|
44
|
+
|
|
45
|
+
* [Building](#building)<br />
|
|
46
|
+
How to build the library and its components yourself.
|
|
47
|
+
|
|
48
|
+
Installation
|
|
49
|
+
---------------
|
|
50
|
+
|
|
51
|
+
### Node.js
|
|
21
52
|
|
|
22
53
|
```sh
|
|
23
|
-
npm install protobufjs
|
|
54
|
+
npm install protobufjs --save
|
|
24
55
|
```
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
```js
|
|
58
|
+
// Static code + Reflection + .proto parser
|
|
59
|
+
var protobuf = require("protobufjs");
|
|
60
|
+
|
|
61
|
+
// Static code + Reflection
|
|
62
|
+
var protobuf = require("protobufjs/light");
|
|
63
|
+
|
|
64
|
+
// Static code only
|
|
65
|
+
var protobuf = require("protobufjs/minimal");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The optional [command line utility](./cli/) to generate static code and reflection bundles lives in the `protobufjs-cli` package and can be installed separately:
|
|
27
69
|
|
|
28
70
|
```sh
|
|
29
|
-
npm install --save-dev
|
|
71
|
+
npm install protobufjs-cli --save-dev
|
|
30
72
|
```
|
|
31
73
|
|
|
32
|
-
|
|
74
|
+
### Browsers
|
|
33
75
|
|
|
34
|
-
|
|
76
|
+
Pick the variant matching your needs and replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon. For example, to use the minified full variant:
|
|
35
77
|
|
|
36
|
-
|
|
78
|
+
```html
|
|
79
|
+
<script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.min.js"></script>
|
|
80
|
+
```
|
|
37
81
|
|
|
38
|
-
|
|
82
|
+
| Distribution | Location
|
|
83
|
+
|--------------|--------------------------------------------------------
|
|
84
|
+
| Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
|
|
85
|
+
| Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
|
|
86
|
+
| Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
|
|
39
87
|
|
|
40
|
-
|
|
88
|
+
All variants support CommonJS and AMD loaders and export globally as `window.protobuf`.
|
|
41
89
|
|
|
42
|
-
|
|
43
|
-
|
|
90
|
+
Usage
|
|
91
|
+
-----
|
|
44
92
|
|
|
45
|
-
|
|
93
|
+
Because JavaScript is a dynamically typed language, protobuf.js utilizes the concept of a **valid message** in order to provide the best possible [performance](#performance) (and, as a side product, proper typings):
|
|
46
94
|
|
|
47
|
-
|
|
48
|
-
string awesome_field = 1;
|
|
49
|
-
}
|
|
50
|
-
```
|
|
95
|
+
### Valid message
|
|
51
96
|
|
|
52
|
-
|
|
97
|
+
> A valid message is an object (1) not missing any required fields and (2) exclusively composed of JS types understood by the wire format writer.
|
|
53
98
|
|
|
54
|
-
|
|
99
|
+
There are two possible types of valid messages and the encoder is able to work with both of these for convenience:
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
|
|
101
|
+
* **Message instances** (explicit instances of message classes with default values on their prototype) naturally satisfy the requirements of a valid message and
|
|
102
|
+
* **Plain JavaScript objects** that just so happen to be composed in a way satisfying the requirements of a valid message as well.
|
|
58
103
|
|
|
59
|
-
|
|
60
|
-
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
61
|
-
```
|
|
104
|
+
In a nutshell, the wire format writer understands the following types:
|
|
62
105
|
|
|
63
|
-
|
|
106
|
+
| Field type | Expected JS type (create, encode) | Conversion (fromObject)
|
|
107
|
+
|------------|-----------------------------------|------------------------
|
|
108
|
+
| s-/u-/int32<br />s-/fixed32 | `number` (32 bit integer) | <code>value | 0</code> if signed<br />`value >>> 0` if unsigned
|
|
109
|
+
| s-/u-/int64<br />s-/fixed64 | `Long`-like (optimal)<br />`number` (53 bit integer) | `Long.fromValue(value)` with long.js<br />`parseInt(value, 10)` otherwise
|
|
110
|
+
| float<br />double | `number` | `Number(value)`
|
|
111
|
+
| bool | `boolean` | `Boolean(value)`
|
|
112
|
+
| string | `string` | `String(value)`
|
|
113
|
+
| bytes | `Uint8Array` (optimal)<br />`Buffer` (optimal under node)<br />`Array.<number>` (8 bit integers) | `base64.decode(value)` if a `string`<br />`Object` with non-zero `.length` is assumed to be buffer-like
|
|
114
|
+
| enum | `number` (32 bit integer) | Looks up the numeric id if a `string`
|
|
115
|
+
| message | Valid message | `Message.fromObject(value)`
|
|
116
|
+
| repeated T | `Array<T>` | Copy
|
|
117
|
+
| map<K, V> | `Object<K,V>` | Copy
|
|
64
118
|
|
|
65
|
-
|
|
119
|
+
* Explicit `undefined` and `null` are considered as not set if the field is optional.
|
|
120
|
+
* Maps are objects where the key is the string representation of the respective value or an 8 characters long hash string for `Long`-likes.
|
|
66
121
|
|
|
67
|
-
|
|
68
|
-
|
|
122
|
+
### Toolset
|
|
123
|
+
|
|
124
|
+
With that in mind and again for performance reasons, each message class provides a distinct set of methods with each method doing just one thing. This avoids unnecessary assertions / redundant operations where performance is a concern but also forces a user to perform verification (of plain JavaScript objects that *might* just so happen to be a valid message) explicitly where necessary - for example when dealing with user input.
|
|
125
|
+
|
|
126
|
+
**Note** that `Message` below refers to any message class.
|
|
127
|
+
|
|
128
|
+
* **Message.verify**(message: `Object`): `null|string`<br />
|
|
129
|
+
verifies that a **plain JavaScript object** satisfies the requirements of a valid message and thus can be encoded without issues. Instead of throwing, it returns the error message as a string, if any.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
var payload = "invalid (not an object)";
|
|
133
|
+
var err = AwesomeMessage.verify(payload);
|
|
134
|
+
if (err)
|
|
135
|
+
throw Error(err);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
* **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
|
|
139
|
+
encodes a **message instance** or valid **plain JavaScript object**. This method does not implicitly verify the message and it's up to the user to make sure that the payload is a valid message.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
var buffer = AwesomeMessage.encode(message).finish();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
* **Message.encodeDelimited**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
|
|
146
|
+
works like `Message.encode` but additionally prepends the length of the message as a varint.
|
|
147
|
+
|
|
148
|
+
* **Message.decode**(reader: `Reader|Uint8Array`): `Message`<br />
|
|
149
|
+
decodes a buffer to a **message instance**. If required fields are missing, it throws a `util.ProtocolError` with an `instance` property set to the so far decoded message. If the wire format is invalid, it throws an `Error`.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
try {
|
|
153
|
+
var decodedMessage = AwesomeMessage.decode(buffer);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof protobuf.util.ProtocolError) {
|
|
156
|
+
// e.instance holds the so far decoded message with missing required fields
|
|
157
|
+
} else {
|
|
158
|
+
// wire format is invalid
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
* **Message.decodeDelimited**(reader: `Reader|Uint8Array`): `Message`<br />
|
|
164
|
+
works like `Message.decode` but additionally reads the length of the message prepended as a varint.
|
|
165
|
+
|
|
166
|
+
* **Message.create**(properties: `Object`): `Message`<br />
|
|
167
|
+
creates a new **message instance** from a set of properties that satisfy the requirements of a valid message. Where applicable, it is recommended to prefer `Message.create` over `Message.fromObject` because it doesn't perform possibly redundant conversion.
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
var message = AwesomeMessage.create({ awesomeField: "AwesomeString" });
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
* **Message.fromObject**(object: `Object`): `Message`<br />
|
|
174
|
+
converts any non-valid **plain JavaScript object** to a **message instance** using the conversion steps outlined within the table above.
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
var message = AwesomeMessage.fromObject({ awesomeField: 42 });
|
|
178
|
+
// converts awesomeField to a string
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
* **Message.toObject**(message: `Message` [, options: `ConversionOptions`]): `Object`<br />
|
|
182
|
+
converts a **message instance** to an arbitrary **plain JavaScript object** for interoperability with other libraries or storage. The resulting plain JavaScript object *might* still satisfy the requirements of a valid message depending on the actual conversion options specified, but most of the time it does not.
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
var object = AwesomeMessage.toObject(message, {
|
|
186
|
+
enums: String, // enums as string names
|
|
187
|
+
longs: String, // longs as strings (or BigInt for bigint values)
|
|
188
|
+
bytes: String, // bytes as base64 encoded strings
|
|
189
|
+
defaults: true, // includes default values
|
|
190
|
+
arrays: true, // populates empty arrays (repeated fields) even if defaults=false
|
|
191
|
+
objects: true, // populates empty objects (map fields) even if defaults=false
|
|
192
|
+
oneofs: true // includes virtual oneof fields set to the present field's name
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
For reference, the following diagram aims to display relationships between the different methods and the concept of a valid message:
|
|
69
197
|
|
|
70
|
-
|
|
71
|
-
const message = AwesomeMessage.create(payload);
|
|
198
|
+
<p align="center"><img alt="Toolset Diagram" src="https://protobufjs.github.io/protobuf.js/toolset.svg" /></p>
|
|
72
199
|
|
|
73
|
-
|
|
74
|
-
|
|
200
|
+
> In other words: `verify` indicates that calling `create` or `encode` directly on the plain object will [result in a valid message respectively] succeed. `fromObject`, on the other hand, does conversion from a broader range of plain objects to create valid messages. ([ref](https://github.com/protobufjs/protobuf.js/issues/748#issuecomment-291925749))
|
|
201
|
+
|
|
202
|
+
Examples
|
|
203
|
+
--------
|
|
204
|
+
|
|
205
|
+
### Using .proto files
|
|
206
|
+
|
|
207
|
+
It is possible to load existing .proto files using the full library, which parses and compiles the definitions to ready to use (reflection-based) message classes:
|
|
208
|
+
|
|
209
|
+
```protobuf
|
|
210
|
+
// awesome.proto
|
|
211
|
+
package awesomepackage;
|
|
212
|
+
syntax = "proto3";
|
|
213
|
+
|
|
214
|
+
message AwesomeMessage {
|
|
215
|
+
string awesome_field = 1; // becomes awesomeField
|
|
216
|
+
}
|
|
75
217
|
```
|
|
76
218
|
|
|
77
|
-
|
|
219
|
+
```js
|
|
220
|
+
protobuf.load("awesome.proto", function(err, root) {
|
|
221
|
+
if (err)
|
|
222
|
+
throw err;
|
|
78
223
|
|
|
79
|
-
|
|
224
|
+
// Obtain a message type
|
|
225
|
+
var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
80
226
|
|
|
81
|
-
|
|
227
|
+
// Exemplary payload
|
|
228
|
+
var payload = { awesomeField: "AwesomeString" };
|
|
82
229
|
|
|
83
|
-
|
|
230
|
+
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
|
|
231
|
+
var errMsg = AwesomeMessage.verify(payload);
|
|
232
|
+
if (errMsg)
|
|
233
|
+
throw Error(errMsg);
|
|
84
234
|
|
|
85
|
-
|
|
235
|
+
// Create a new message
|
|
236
|
+
var message = AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
|
|
86
237
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
238
|
+
// Encode a message to an Uint8Array (browser) or Buffer (node)
|
|
239
|
+
var buffer = AwesomeMessage.encode(message).finish();
|
|
240
|
+
// ... do something with buffer
|
|
241
|
+
|
|
242
|
+
// Decode an Uint8Array (browser) or Buffer (node) to a message
|
|
243
|
+
var message = AwesomeMessage.decode(buffer);
|
|
244
|
+
// ... do something with message
|
|
245
|
+
|
|
246
|
+
// If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
|
|
247
|
+
|
|
248
|
+
// Maybe convert the message back to a plain object
|
|
249
|
+
var object = AwesomeMessage.toObject(message, {
|
|
250
|
+
longs: String,
|
|
251
|
+
enums: String,
|
|
252
|
+
bytes: String,
|
|
253
|
+
// see ConversionOptions
|
|
254
|
+
});
|
|
93
255
|
});
|
|
94
256
|
```
|
|
95
257
|
|
|
96
|
-
|
|
258
|
+
Additionally, promise syntax can be used by omitting the callback, if preferred:
|
|
97
259
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
| `bytes: String` | Converts bytes to base64 strings |
|
|
105
|
-
| `defaults: true` | Includes default values for unset fields |
|
|
106
|
-
| `arrays: true` | Includes empty arrays for repeated fields |
|
|
107
|
-
| `objects: true` | Includes empty objects for map fields |
|
|
108
|
-
| `oneofs: true` | Includes virtual oneof discriminator properties |
|
|
260
|
+
```js
|
|
261
|
+
protobuf.load("awesome.proto")
|
|
262
|
+
.then(function(root) {
|
|
263
|
+
...
|
|
264
|
+
});
|
|
265
|
+
```
|
|
109
266
|
|
|
110
|
-
|
|
267
|
+
### Using JSON descriptors
|
|
268
|
+
|
|
269
|
+
The library utilizes JSON descriptors that are equivalent to a .proto definition. For example, the following is identical to the .proto definition seen above:
|
|
270
|
+
|
|
271
|
+
```json
|
|
272
|
+
// awesome.json
|
|
273
|
+
{
|
|
274
|
+
"nested": {
|
|
275
|
+
"awesomepackage": {
|
|
276
|
+
"nested": {
|
|
277
|
+
"AwesomeMessage": {
|
|
278
|
+
"fields": {
|
|
279
|
+
"awesomeField": {
|
|
280
|
+
"type": "string",
|
|
281
|
+
"id": 1
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
111
290
|
|
|
112
|
-
|
|
291
|
+
JSON descriptors closely resemble the internal reflection structure:
|
|
113
292
|
|
|
114
|
-
|
|
115
|
-
|
|
293
|
+
| Type (T) | Extends | Type-specific properties
|
|
294
|
+
|--------------------|--------------------|-------------------------
|
|
295
|
+
| *ReflectionObject* | | options
|
|
296
|
+
| *Namespace* | *ReflectionObject* | nested
|
|
297
|
+
| Root | *Namespace* | **nested**
|
|
298
|
+
| Type | *Namespace* | **fields**
|
|
299
|
+
| Enum | *ReflectionObject* | **values**
|
|
300
|
+
| Field | *ReflectionObject* | rule, **type**, **id**
|
|
301
|
+
| MapField | Field | **keyType**
|
|
302
|
+
| OneOf | *ReflectionObject* | **oneof** (array of field names)
|
|
303
|
+
| Service | *Namespace* | **methods**
|
|
304
|
+
| Method | *ReflectionObject* | type, **requestType**, **responseType**, requestStream, responseStream
|
|
116
305
|
|
|
117
|
-
* **
|
|
118
|
-
|
|
306
|
+
* **Bold properties** are required. *Italic types* are abstract.
|
|
307
|
+
* `T.fromJSON(name, json)` creates the respective reflection object from a JSON descriptor
|
|
308
|
+
* `T#toJSON()` creates a JSON descriptor from the respective reflection object (its name is used as the key within the parent)
|
|
119
309
|
|
|
120
|
-
|
|
121
|
-
Decodes a message from protobuf binary data.
|
|
310
|
+
Exclusively using JSON descriptors instead of .proto files enables the use of just the light library (the parser isn't required in this case).
|
|
122
311
|
|
|
123
|
-
|
|
124
|
-
Decodes a length-delimited message.
|
|
312
|
+
A JSON descriptor can either be loaded the usual way:
|
|
125
313
|
|
|
126
|
-
|
|
127
|
-
|
|
314
|
+
```js
|
|
315
|
+
protobuf.load("awesome.json", function(err, root) {
|
|
316
|
+
if (err) throw err;
|
|
128
317
|
|
|
129
|
-
|
|
130
|
-
|
|
318
|
+
// Continue at "Obtain a message type" above
|
|
319
|
+
});
|
|
320
|
+
```
|
|
131
321
|
|
|
132
|
-
|
|
133
|
-
Converts broader JavaScript input into a message instance.
|
|
322
|
+
Or it can be loaded inline:
|
|
134
323
|
|
|
135
|
-
|
|
136
|
-
|
|
324
|
+
```js
|
|
325
|
+
var jsonDescriptor = require("./awesome.json"); // exemplary for node
|
|
137
326
|
|
|
138
|
-
|
|
139
|
-
Converts a message instance to JSON-compatible output using default conversion options.
|
|
327
|
+
var root = protobuf.Root.fromJSON(jsonDescriptor);
|
|
140
328
|
|
|
141
|
-
|
|
329
|
+
// Continue at "Obtain a message type" above
|
|
330
|
+
```
|
|
142
331
|
|
|
143
|
-
|
|
332
|
+
### Using reflection only
|
|
144
333
|
|
|
145
|
-
|
|
334
|
+
Both the full and the light library include full reflection support. One could, for example, define the .proto definitions seen in the examples above using just reflection:
|
|
146
335
|
|
|
147
|
-
|
|
336
|
+
```js
|
|
337
|
+
...
|
|
338
|
+
var Root = protobuf.Root,
|
|
339
|
+
Type = protobuf.Type,
|
|
340
|
+
Field = protobuf.Field;
|
|
148
341
|
|
|
149
|
-
|
|
342
|
+
var AwesomeMessage = new Type("AwesomeMessage").add(new Field("awesomeField", 1, "string"));
|
|
150
343
|
|
|
151
|
-
|
|
152
|
-
| ----------------------- | ------------------ | --------
|
|
153
|
-
| `protobufjs` | Reflection, Parser | You load `.proto` files at runtime
|
|
154
|
-
| `protobufjs/light.js` | Reflection | You load JSON bundles or build schemas programmatically
|
|
155
|
-
| `protobufjs/minimal.js` | Static runtime | You use generated static code
|
|
344
|
+
var root = new Root().define("awesomepackage").add(AwesomeMessage);
|
|
156
345
|
|
|
157
|
-
|
|
346
|
+
// Continue at "Create a new message" above
|
|
347
|
+
...
|
|
348
|
+
```
|
|
158
349
|
|
|
159
|
-
|
|
350
|
+
Detailed information on the reflection structure is available within the [API documentation](#additional-documentation).
|
|
160
351
|
|
|
161
|
-
|
|
352
|
+
### Using custom classes
|
|
162
353
|
|
|
163
|
-
|
|
354
|
+
Message classes can also be extended with custom functionality and it is also possible to register a custom constructor with a reflected message type:
|
|
164
355
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
| `json` | JSON bundle | `protobufjs/light.js` |
|
|
168
|
-
| `json-module` | JSON bundle module | `protobufjs/light.js` |
|
|
169
|
-
| `static-module` | Static code module | `protobufjs/minimal.js` |
|
|
356
|
+
```js
|
|
357
|
+
...
|
|
170
358
|
|
|
171
|
-
|
|
359
|
+
// Define a custom constructor
|
|
360
|
+
function AwesomeMessage(properties) {
|
|
361
|
+
// custom initialization code
|
|
362
|
+
...
|
|
363
|
+
}
|
|
172
364
|
|
|
173
|
-
|
|
365
|
+
// Register the custom constructor with its reflected type (*)
|
|
366
|
+
root.lookupType("awesomepackage.AwesomeMessage").ctor = AwesomeMessage;
|
|
174
367
|
|
|
175
|
-
|
|
368
|
+
// Define custom functionality
|
|
369
|
+
AwesomeMessage.customStaticMethod = function() { ... };
|
|
370
|
+
AwesomeMessage.prototype.customInstanceMethod = function() { ... };
|
|
176
371
|
|
|
177
|
-
|
|
178
|
-
npx pbjs -t static-module -w esm -o awesome.js --dts awesome.proto
|
|
372
|
+
// Continue at "Create a new message" above
|
|
179
373
|
```
|
|
180
374
|
|
|
181
|
-
|
|
182
|
-
import { awesomepackage } from "./awesome.js";
|
|
375
|
+
(*) Besides referencing its reflected type through `AwesomeMessage.$type` and `AwesomeMesage#$type`, the respective custom class is automatically populated with:
|
|
183
376
|
|
|
184
|
-
|
|
185
|
-
|
|
377
|
+
* `AwesomeMessage.create`
|
|
378
|
+
* `AwesomeMessage.encode` and `AwesomeMessage.encodeDelimited`
|
|
379
|
+
* `AwesomeMessage.decode` and `AwesomeMessage.decodeDelimited`
|
|
380
|
+
* `AwesomeMessage.verify`
|
|
381
|
+
* `AwesomeMessage.fromObject`, `AwesomeMessage.toObject` and `AwesomeMessage#toJSON`
|
|
186
382
|
|
|
187
|
-
|
|
383
|
+
Afterwards, decoded messages of this type are `instanceof AwesomeMessage`.
|
|
188
384
|
|
|
189
|
-
|
|
385
|
+
Alternatively, it is also possible to reuse and extend the internal constructor if custom initialization code is not required:
|
|
190
386
|
|
|
191
|
-
|
|
387
|
+
```js
|
|
388
|
+
...
|
|
192
389
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
```
|
|
390
|
+
// Reuse the internal constructor
|
|
391
|
+
var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage").ctor;
|
|
196
392
|
|
|
197
|
-
|
|
198
|
-
|
|
393
|
+
// Define custom functionality
|
|
394
|
+
AwesomeMessage.customStaticMethod = function() { ... };
|
|
395
|
+
AwesomeMessage.prototype.customInstanceMethod = function() { ... };
|
|
199
396
|
|
|
200
|
-
|
|
201
|
-
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
397
|
+
// Continue at "Create a new message" above
|
|
202
398
|
```
|
|
203
399
|
|
|
204
|
-
|
|
205
|
-
|
|
400
|
+
### Using services
|
|
401
|
+
|
|
402
|
+
The library also supports consuming services but it doesn't make any assumptions about the actual transport channel. Instead, a user must provide a suitable RPC implementation, which is an asynchronous function that takes the reflected service method, the binary request and a node-style callback as its parameters:
|
|
403
|
+
|
|
404
|
+
```js
|
|
405
|
+
function rpcImpl(method, requestData, callback) {
|
|
406
|
+
// perform the request using an HTTP request or a WebSocket for example
|
|
407
|
+
var responseData = ...;
|
|
408
|
+
// and call the callback with the binary response afterwards:
|
|
409
|
+
callback(null, responseData);
|
|
410
|
+
}
|
|
206
411
|
```
|
|
207
412
|
|
|
413
|
+
Below is a working example with a typescript implementation using grpc npm package.
|
|
208
414
|
```ts
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
415
|
+
const grpc = require('grpc')
|
|
416
|
+
|
|
417
|
+
const Client = grpc.makeGenericClientConstructor({})
|
|
418
|
+
const client = new Client(
|
|
419
|
+
grpcServerUrl,
|
|
420
|
+
grpc.credentials.createInsecure()
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
const rpcImpl = function(method, requestData, callback) {
|
|
424
|
+
client.makeUnaryRequest(
|
|
425
|
+
method.name,
|
|
426
|
+
arg => arg,
|
|
427
|
+
arg => arg,
|
|
428
|
+
requestData,
|
|
429
|
+
callback
|
|
430
|
+
)
|
|
431
|
+
}
|
|
212
432
|
```
|
|
213
433
|
|
|
214
|
-
|
|
434
|
+
Example:
|
|
215
435
|
|
|
216
|
-
|
|
436
|
+
```protobuf
|
|
437
|
+
// greeter.proto
|
|
438
|
+
syntax = "proto3";
|
|
217
439
|
|
|
218
|
-
|
|
440
|
+
service Greeter {
|
|
441
|
+
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
|
442
|
+
}
|
|
219
443
|
|
|
220
|
-
|
|
444
|
+
message HelloRequest {
|
|
445
|
+
string name = 1;
|
|
446
|
+
}
|
|
221
447
|
|
|
222
|
-
|
|
223
|
-
message
|
|
224
|
-
oneof contact {
|
|
225
|
-
string email = 1;
|
|
226
|
-
string phone = 2;
|
|
227
|
-
}
|
|
448
|
+
message HelloReply {
|
|
449
|
+
string message = 1;
|
|
228
450
|
}
|
|
229
451
|
```
|
|
230
452
|
|
|
231
|
-
|
|
453
|
+
```js
|
|
454
|
+
...
|
|
455
|
+
var Greeter = root.lookup("Greeter");
|
|
456
|
+
var greeter = Greeter.create(/* see above */ rpcImpl, /* request delimited? */ false, /* response delimited? */ false);
|
|
232
457
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
contact: "email",
|
|
236
|
-
email: "hello@example.com"
|
|
458
|
+
greeter.sayHello({ name: 'you' }, function(err, response) {
|
|
459
|
+
console.log('Greeting:', response.message);
|
|
237
460
|
});
|
|
461
|
+
```
|
|
238
462
|
|
|
239
|
-
|
|
240
|
-
profile.email; // string
|
|
241
|
-
}
|
|
463
|
+
Services also support promises:
|
|
242
464
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
465
|
+
```js
|
|
466
|
+
greeter.sayHello({ name: 'you' })
|
|
467
|
+
.then(function(response) {
|
|
468
|
+
console.log('Greeting:', response.message);
|
|
469
|
+
});
|
|
247
470
|
```
|
|
248
471
|
|
|
249
|
-
|
|
472
|
+
There is also an [example for streaming RPC](https://github.com/protobufjs/protobuf.js/blob/master/examples/streaming-rpc.js).
|
|
250
473
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
email: "hello@example.com"
|
|
255
|
-
};
|
|
256
|
-
```
|
|
474
|
+
Note that the service API is meant for clients. Implementing a server-side endpoint pretty much always requires transport channel (i.e. http, websocket, etc.) specific code with the only common denominator being that it decodes and encodes messages.
|
|
475
|
+
|
|
476
|
+
### Usage with TypeScript
|
|
257
477
|
|
|
258
|
-
|
|
478
|
+
The library ships with its own [type definitions](https://github.com/protobufjs/protobuf.js/blob/master/index.d.ts) and modern editors like [Visual Studio Code](https://code.visualstudio.com/) will automatically detect and use them for code completion.
|
|
259
479
|
|
|
260
|
-
|
|
480
|
+
The npm package depends on [@types/node](https://www.npmjs.com/package/@types/node) because of `Buffer` and [@types/long](https://www.npmjs.com/package/@types/long) because of `Long`. If you are not building for node and/or not using long.js, it should be safe to exclude them manually.
|
|
261
481
|
|
|
262
|
-
|
|
482
|
+
#### Using the JS API
|
|
483
|
+
|
|
484
|
+
The API shown above works pretty much the same with TypeScript. However, because everything is typed, accessing fields on instances of dynamically generated message classes requires either using bracket-notation (i.e. `message["awesomeField"]`) or explicit casts. Alternatively, it is possible to use a [typings file generated for its static counterpart](#pbts-for-typescript).
|
|
263
485
|
|
|
264
486
|
```ts
|
|
265
|
-
|
|
266
|
-
|
|
487
|
+
import { load } from "protobufjs"; // respectively "./node_modules/protobufjs"
|
|
488
|
+
|
|
489
|
+
load("awesome.proto", function(err, root) {
|
|
490
|
+
if (err)
|
|
491
|
+
throw err;
|
|
267
492
|
|
|
268
|
-
|
|
269
|
-
.
|
|
270
|
-
|
|
493
|
+
// example code
|
|
494
|
+
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
495
|
+
|
|
496
|
+
let message = AwesomeMessage.create({ awesomeField: "hello" });
|
|
497
|
+
console.log(`message = ${JSON.stringify(message)}`);
|
|
498
|
+
|
|
499
|
+
let buffer = AwesomeMessage.encode(message).finish();
|
|
500
|
+
console.log(`buffer = ${Array.prototype.toString.call(buffer)}`);
|
|
501
|
+
|
|
502
|
+
let decoded = AwesomeMessage.decode(buffer);
|
|
503
|
+
console.log(`decoded = ${JSON.stringify(decoded)}`);
|
|
504
|
+
});
|
|
271
505
|
```
|
|
272
506
|
|
|
273
|
-
|
|
507
|
+
#### Using generated static code
|
|
274
508
|
|
|
275
|
-
|
|
509
|
+
If you generated static code to `bundle.js` using the CLI and its type definitions to `bundle.d.ts`, then you can just do:
|
|
276
510
|
|
|
277
511
|
```ts
|
|
278
|
-
|
|
279
|
-
awesomeField = "";
|
|
512
|
+
import { AwesomeMessage } from "./bundle.js";
|
|
280
513
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
514
|
+
// example code
|
|
515
|
+
let message = AwesomeMessage.create({ awesomeField: "hello" });
|
|
516
|
+
let buffer = AwesomeMessage.encode(message).finish();
|
|
517
|
+
let decoded = AwesomeMessage.decode(buffer);
|
|
518
|
+
```
|
|
285
519
|
|
|
286
|
-
|
|
287
|
-
return this.awesomeField.toLowerCase();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
520
|
+
#### Using decorators
|
|
290
521
|
|
|
291
|
-
|
|
522
|
+
The library also includes an early implementation of [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html).
|
|
292
523
|
|
|
293
|
-
|
|
294
|
-
decoded.customInstanceMethod(); // string
|
|
295
|
-
```
|
|
524
|
+
**Note** that decorators are an experimental feature in TypeScript and that declaration order is important depending on the JS target. For example, `@Field.d(2, AwesomeArrayMessage)` requires that `AwesomeArrayMessage` has been defined earlier when targeting `ES5`.
|
|
296
525
|
|
|
297
|
-
|
|
526
|
+
```ts
|
|
527
|
+
import { Message, Type, Field, OneOf } from "protobufjs/light"; // respectively "./node_modules/protobufjs/light.js"
|
|
298
528
|
|
|
299
|
-
|
|
529
|
+
export class AwesomeSubMessage extends Message<AwesomeSubMessage> {
|
|
300
530
|
|
|
301
|
-
|
|
531
|
+
@Field.d(1, "string")
|
|
532
|
+
public awesomeString: string;
|
|
302
533
|
|
|
303
|
-
```js
|
|
304
|
-
function myRpcImpl(method, requestData, callback) {
|
|
305
|
-
// method.name
|
|
306
|
-
// method.path
|
|
307
|
-
// method.requestStream?
|
|
308
|
-
// method.responseStream?
|
|
309
|
-
performRequest(requestData, function(err, responseData) {
|
|
310
|
-
callback(err, responseData);
|
|
311
|
-
});
|
|
312
534
|
}
|
|
313
535
|
|
|
314
|
-
|
|
315
|
-
|
|
536
|
+
export enum AwesomeEnum {
|
|
537
|
+
ONE = 1,
|
|
538
|
+
TWO = 2
|
|
539
|
+
}
|
|
316
540
|
|
|
317
|
-
|
|
541
|
+
@Type.d("SuperAwesomeMessage")
|
|
542
|
+
export class AwesomeMessage extends Message<AwesomeMessage> {
|
|
318
543
|
|
|
319
|
-
|
|
544
|
+
@Field.d(1, "string", "optional", "awesome default string")
|
|
545
|
+
public awesomeField: string;
|
|
320
546
|
|
|
321
|
-
|
|
322
|
-
|
|
547
|
+
@Field.d(2, AwesomeSubMessage)
|
|
548
|
+
public awesomeSubMessage: AwesomeSubMessage;
|
|
323
549
|
|
|
324
|
-
|
|
325
|
-
|
|
550
|
+
@Field.d(3, AwesomeEnum, "optional", AwesomeEnum.ONE)
|
|
551
|
+
public awesomeEnum: AwesomeEnum;
|
|
326
552
|
|
|
327
|
-
|
|
328
|
-
|
|
553
|
+
@OneOf.d("awesomeSubMessage", "awesomeEnum")
|
|
554
|
+
public which: string;
|
|
329
555
|
|
|
330
|
-
|
|
331
|
-
const reply = await greeter.sayHello({ name: "world" });
|
|
332
|
-
```
|
|
556
|
+
}
|
|
333
557
|
|
|
334
|
-
|
|
558
|
+
// example code
|
|
559
|
+
let message = new AwesomeMessage({ awesomeField: "hello" });
|
|
560
|
+
let buffer = AwesomeMessage.encode(message).finish();
|
|
561
|
+
let decoded = AwesomeMessage.decode(buffer);
|
|
562
|
+
```
|
|
335
563
|
|
|
336
|
-
|
|
564
|
+
Supported decorators are:
|
|
337
565
|
|
|
338
|
-
|
|
566
|
+
* **Type.d(typeName?: `string`)** *(optional)*<br />
|
|
567
|
+
annotates a class as a protobuf message type. If `typeName` is not specified, the constructor's runtime function name is used for the reflected type.
|
|
339
568
|
|
|
340
|
-
|
|
569
|
+
* **Field.d<T>(fieldId: `number`, fieldType: `string | Constructor<T>`, fieldRule?: `"optional" | "required" | "repeated"`, defaultValue?: `T`)**<br />
|
|
570
|
+
annotates a property as a protobuf field with the specified id and protobuf type.
|
|
341
571
|
|
|
342
|
-
|
|
572
|
+
* **MapField.d<T extends { [key: string]: any }>(fieldId: `number`, fieldKeyType: `string`, fieldValueType. `string | Constructor<{}>`)**<br />
|
|
573
|
+
annotates a property as a protobuf map field with the specified id, protobuf key and value type.
|
|
343
574
|
|
|
344
|
-
|
|
575
|
+
* **OneOf.d<T extends string>(...fieldNames: `string[]`)**<br />
|
|
576
|
+
annotates a property as a protobuf oneof covering the specified fields.
|
|
345
577
|
|
|
346
|
-
|
|
578
|
+
Other notes:
|
|
347
579
|
|
|
348
|
-
|
|
580
|
+
* Decorated types reside in `protobuf.roots["decorated"]` using a flat structure, so no duplicate names.
|
|
581
|
+
* Enums are copied to a reflected enum with a generic name on decorator evaluation because referenced enum objects have no runtime name the decorator could use.
|
|
582
|
+
* Default values must be specified as arguments to the decorator instead of using a property initializer for proper prototype behavior.
|
|
583
|
+
* Property names on decorated classes must not be renamed on compile time (i.e. by a minifier) because decorators just receive the original field name as a string.
|
|
349
584
|
|
|
350
|
-
|
|
585
|
+
**ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/protobufjs/protobuf.js/blob/master/examples/js-decorators.js) as well.
|
|
351
586
|
|
|
352
|
-
|
|
587
|
+
Additional documentation
|
|
588
|
+
------------------------
|
|
353
589
|
|
|
354
|
-
|
|
590
|
+
#### Protocol Buffers
|
|
591
|
+
* [Google's Developer Guide](https://protobuf.dev/overview/)
|
|
355
592
|
|
|
356
|
-
|
|
593
|
+
#### protobuf.js
|
|
594
|
+
* [API Documentation](https://protobufjs.github.io/protobuf.js)
|
|
595
|
+
* [CHANGELOG](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md)
|
|
596
|
+
* [Frequently asked questions](https://github.com/protobufjs/protobuf.js/wiki) on our wiki
|
|
357
597
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
| Binary | 100.00% (2835/2835) | 100.00% (1958/1958) | 100.00% (877/877) |
|
|
361
|
-
| ↳ Proto2 | 100.00% (707/707) | 100.00% (489/489) | 100.00% (218/218) |
|
|
362
|
-
| ↳ Proto3 | 100.00% (707/707) | 100.00% (486/486) | 100.00% (221/221) |
|
|
363
|
-
| ↳ Editions | 100.00% (1421/1421) | 100.00% (983/983) | 100.00% (438/438) |
|
|
364
|
-
| ProtoJSON | 100.00% (2796/2796) | 100.00% (2362/2362) | 100.00% (434/434) |
|
|
365
|
-
| TextFormat | 100.00% (909/909) | 100.00% (845/845) | 100.00% (64/64) |
|
|
366
|
-
| Overall | 100.00% (6540/6540) | 100.00% (5165/5165) | 100.00% (1375/1375) |
|
|
598
|
+
#### Community
|
|
599
|
+
* [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
|
|
367
600
|
|
|
368
|
-
|
|
601
|
+
Performance
|
|
602
|
+
-----------
|
|
603
|
+
The package includes a benchmark that compares protobuf.js performance to native JSON (as far as this is possible) and [Google's JS implementation](https://github.com/google/protobuf/tree/master/js). On an i7-2600K running node 6.9.1 it yields:
|
|
369
604
|
|
|
370
|
-
|
|
605
|
+
```
|
|
606
|
+
benchmarking encoding performance ...
|
|
607
|
+
|
|
608
|
+
protobuf.js (reflect) x 541,707 ops/sec ±1.13% (87 runs sampled)
|
|
609
|
+
protobuf.js (static) x 548,134 ops/sec ±1.38% (89 runs sampled)
|
|
610
|
+
JSON (string) x 318,076 ops/sec ±0.63% (93 runs sampled)
|
|
611
|
+
JSON (buffer) x 179,165 ops/sec ±2.26% (91 runs sampled)
|
|
612
|
+
google-protobuf x 74,406 ops/sec ±0.85% (86 runs sampled)
|
|
613
|
+
|
|
614
|
+
protobuf.js (static) was fastest
|
|
615
|
+
protobuf.js (reflect) was 0.9% ops/sec slower (factor 1.0)
|
|
616
|
+
JSON (string) was 41.5% ops/sec slower (factor 1.7)
|
|
617
|
+
JSON (buffer) was 67.6% ops/sec slower (factor 3.1)
|
|
618
|
+
google-protobuf was 86.4% ops/sec slower (factor 7.3)
|
|
619
|
+
|
|
620
|
+
benchmarking decoding performance ...
|
|
621
|
+
|
|
622
|
+
protobuf.js (reflect) x 1,383,981 ops/sec ±0.88% (93 runs sampled)
|
|
623
|
+
protobuf.js (static) x 1,378,925 ops/sec ±0.81% (93 runs sampled)
|
|
624
|
+
JSON (string) x 302,444 ops/sec ±0.81% (93 runs sampled)
|
|
625
|
+
JSON (buffer) x 264,882 ops/sec ±0.81% (93 runs sampled)
|
|
626
|
+
google-protobuf x 179,180 ops/sec ±0.64% (94 runs sampled)
|
|
627
|
+
|
|
628
|
+
protobuf.js (reflect) was fastest
|
|
629
|
+
protobuf.js (static) was 0.3% ops/sec slower (factor 1.0)
|
|
630
|
+
JSON (string) was 78.1% ops/sec slower (factor 4.6)
|
|
631
|
+
JSON (buffer) was 80.8% ops/sec slower (factor 5.2)
|
|
632
|
+
google-protobuf was 87.0% ops/sec slower (factor 7.7)
|
|
633
|
+
|
|
634
|
+
benchmarking combined performance ...
|
|
635
|
+
|
|
636
|
+
protobuf.js (reflect) x 275,900 ops/sec ±0.78% (90 runs sampled)
|
|
637
|
+
protobuf.js (static) x 290,096 ops/sec ±0.96% (90 runs sampled)
|
|
638
|
+
JSON (string) x 129,381 ops/sec ±0.77% (90 runs sampled)
|
|
639
|
+
JSON (buffer) x 91,051 ops/sec ±0.94% (90 runs sampled)
|
|
640
|
+
google-protobuf x 42,050 ops/sec ±0.85% (91 runs sampled)
|
|
641
|
+
|
|
642
|
+
protobuf.js (static) was fastest
|
|
643
|
+
protobuf.js (reflect) was 4.7% ops/sec slower (factor 1.0)
|
|
644
|
+
JSON (string) was 55.3% ops/sec slower (factor 2.2)
|
|
645
|
+
JSON (buffer) was 68.6% ops/sec slower (factor 3.2)
|
|
646
|
+
google-protobuf was 85.5% ops/sec slower (factor 6.9)
|
|
647
|
+
```
|
|
371
648
|
|
|
372
|
-
|
|
649
|
+
These results are achieved by
|
|
373
650
|
|
|
374
|
-
|
|
651
|
+
* generating type-specific encoders, decoders, verifiers and converters at runtime
|
|
652
|
+
* configuring the reader/writer interface according to the environment
|
|
653
|
+
* using node-specific functionality where beneficial and, of course
|
|
654
|
+
* avoiding unnecessary operations through splitting up [the toolset](#toolset).
|
|
375
655
|
|
|
376
|
-
|
|
656
|
+
You can also run [the benchmark](https://github.com/protobufjs/protobuf.js/blob/master/bench/index.js) ...
|
|
377
657
|
|
|
378
|
-
|
|
658
|
+
```
|
|
659
|
+
$> npm run bench
|
|
660
|
+
```
|
|
379
661
|
|
|
380
|
-
|
|
662
|
+
and [the profiler](https://github.com/protobufjs/protobuf.js/blob/master/bench/prof.js) yourself (the latter requires a recent version of node):
|
|
381
663
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
| Vector tile | 2.82K ops/s | 2.76K ops/s | 859 ops/s | 680 ops/s | 231 ops/s |
|
|
386
|
-
| Buf perf | 41.4K ops/s | 39.9K ops/s | 6.59K ops/s | 13.5K ops/s | 8.00K ops/s |
|
|
664
|
+
```
|
|
665
|
+
$> npm run prof <encode|decode|encode-browser|decode-browser> [iterations=10000000]
|
|
666
|
+
```
|
|
387
667
|
|
|
388
|
-
|
|
668
|
+
Note that as of this writing, the benchmark suite performs significantly slower on node 7.2.0 compared to 6.9.1 because moths.
|
|
389
669
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
| Common | 6.11M ops/s | 6.09M ops/s | 1.31M ops/s | 790K ops/s | 710K ops/s |
|
|
393
|
-
| Vector tile | 2.45K ops/s | 2.78K ops/s | 1.04K ops/s | 858 ops/s | 392 ops/s |
|
|
394
|
-
| Buf perf | 72.5K ops/s | 66.4K ops/s | 19.0K ops/s | 21.1K ops/s | 14.2K ops/s |
|
|
670
|
+
Compatibility
|
|
671
|
+
-------------
|
|
395
672
|
|
|
396
|
-
|
|
673
|
+
* Works in all modern and not-so-modern browsers except IE8.
|
|
674
|
+
* Because the internals of this package do not rely on `google/protobuf/descriptor.proto`, options are parsed and presented literally.
|
|
675
|
+
* If typed arrays are not supported by the environment, plain arrays will be used instead.
|
|
676
|
+
* Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/protobufjs/protobuf.js/blob/master/lib/polyfill.js).
|
|
677
|
+
* Support for [Content Security Policy](https://w3c.github.io/webappsec-csp/)-restricted environments (like Chrome extensions without unsafe-eval) can be achieved by generating and using static code instead.
|
|
678
|
+
* If a proper way to work with 64 bit values (uint64, int64 etc.) is required, just install [long.js](https://github.com/dcodeIO/long.js) alongside this library. All 64 bit numbers will then be returned as a `Long` instance instead of a possibly unsafe JavaScript number ([see](https://github.com/dcodeIO/long.js)).
|
|
679
|
+
* For descriptor.proto interoperability, see [ext/descriptor](https://github.com/protobufjs/protobuf.js/tree/master/ext/descriptor)
|
|
397
680
|
|
|
398
|
-
|
|
681
|
+
Building
|
|
682
|
+
--------
|
|
399
683
|
|
|
400
|
-
To
|
|
684
|
+
To build the library or its components yourself, clone it from GitHub and install the development dependencies:
|
|
401
685
|
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
|
|
686
|
+
```
|
|
687
|
+
$> git clone https://github.com/protobufjs/protobuf.js.git
|
|
688
|
+
$> cd protobuf.js
|
|
689
|
+
$> npm install
|
|
405
690
|
```
|
|
406
691
|
|
|
407
|
-
|
|
692
|
+
Building the respective development and production versions with their respective source maps to `dist/`:
|
|
408
693
|
|
|
409
|
-
|
|
694
|
+
```
|
|
695
|
+
$> npm run build
|
|
696
|
+
```
|
|
410
697
|
|
|
411
|
-
|
|
698
|
+
Building the documentation to `docs/`:
|
|
412
699
|
|
|
413
|
-
|
|
700
|
+
```
|
|
701
|
+
$> npm run docs
|
|
702
|
+
```
|
|
414
703
|
|
|
415
|
-
|
|
704
|
+
Building the TypeScript definition to `index.d.ts`:
|
|
416
705
|
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
cd protobuf.js
|
|
420
|
-
npm install
|
|
421
|
-
npm --prefix cli install
|
|
706
|
+
```
|
|
707
|
+
$> npm run build:types
|
|
422
708
|
```
|
|
423
709
|
|
|
424
|
-
|
|
710
|
+
### Browserify integration
|
|
425
711
|
|
|
426
|
-
|
|
427
|
-
npm test
|
|
428
|
-
```
|
|
712
|
+
By default, protobuf.js integrates into any browserify build-process without requiring any optional modules. Hence:
|
|
429
713
|
|
|
430
|
-
|
|
714
|
+
* If int64 support is required, explicitly require the `long` module somewhere in your project as it will be excluded otherwise. This assumes that a global `require` function is present that protobuf.js can call to obtain the long module.
|
|
431
715
|
|
|
432
|
-
|
|
433
|
-
npm run build
|
|
434
|
-
```
|
|
716
|
+
If there is no global `require` function present after bundling, it's also possible to assign the long module programmatically:
|
|
435
717
|
|
|
436
|
-
|
|
718
|
+
```js
|
|
719
|
+
var Long = ...;
|
|
437
720
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
721
|
+
protobuf.util.Long = Long;
|
|
722
|
+
protobuf.configure();
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
* If you have any special requirements, there is [the bundler](https://github.com/protobufjs/protobuf.js/blob/master/scripts/bundle.js) for reference.
|
|
726
|
+
|
|
727
|
+
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
|