@openclaw/whatsapp 2026.8.1-beta.3 → 2026.8.2
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/{accounts-BX2fZUyR.js → accounts-CeKQbu_s.js} +9 -26
- package/dist/{action-runtime-pM-ExU0l.js → action-runtime-Bw0loEdy.js} +2 -2
- 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} +13 -6
- package/dist/{agent-tools-login-BjRpD-JQ.js → agent-tools-login-B-2qZPzc.js} +12 -3
- package/dist/api.js +10 -10
- package/dist/{approval-handler.runtime-CkMMvUjk.js → approval-handler.runtime-DeyPb57-.js} +3 -3
- package/dist/{approval-reactions-Jyr1JaAK.js → approval-reactions-DGDA6hQ7.js} +7 -5
- package/dist/{auth-store-CtpBqH5S.js → auth-store-DTj1H9pv.js} +5 -3
- package/dist/{channel-DRMYRfZ8.js → channel-DxMmDjqK.js} +26 -24
- package/dist/channel-config-api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel-react-action-CstrR0CT.js → channel-react-action-BUp7Wbfr.js} +3 -3
- package/dist/{channel.runtime-X3JC2gaq.js → channel.runtime-BwSnyXRX.js} +4 -4
- package/dist/{channel.setup-DhBBhbQv.js → channel.setup-aOFLSQyw.js} +1 -1
- package/dist/{config-schema-BQP5YCeK.js → config-schema-BYA6e_Ii.js} +6 -4
- package/dist/{connection-controller-CIYuBJrs.js → connection-controller-BvkxsbWi.js} +2 -2
- package/dist/{constants-HU41RHGI.js → constants-C7m81BNe.js} +1 -1
- package/dist/{directory-config-P7_3U73Z.js → directory-config-LgxYJLWY.js} +3 -3
- package/dist/directory-contract-api.js +1 -1
- package/dist/{group-session-key-DmFc_Cqi.js → group-session-key-KUguLmSZ.js} +4 -4
- package/dist/index.js +4 -4
- package/dist/light-runtime-api.js +2 -2
- package/dist/{login-BkpKpndm.js → login-Bk_jiXKD.js} +6 -5
- package/dist/{login-qr-1dpv6jjT.js → login-qr-B3m61NqA.js} +43 -20
- package/dist/login-qr-runtime.js +1 -1
- package/dist/{monitor-IzwQKizW.js → monitor-CTsyo-HE.js} +185 -162
- package/dist/{question-reactions-D3eAeB0i.js → question-reactions-B9D6MHXZ.js} +1 -1
- package/dist/runtime-api.js +9 -9
- package/dist/{send-CwvTU4RI.js → send-DiPjiygK.js} +54 -29
- package/dist/{send-api-obOSm2cC.js → send-api-kFcuhSiY.js} +43 -41
- package/dist/{setup-finalize-n4K2I2gJ.js → setup-finalize-CqH5wTK5.js} +7 -6
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-Cwn3zyxK.js → setup-surface-Dm3T6S8t.js} +3 -3
- package/dist/{shared-wg42NKFB.js → shared-DDjonGys.js} +7 -6
- package/dist/{socket-close-2T0_jZTN.js → socket-close-CpkkJZCU.js} +9 -6
- package/dist/{targets-runtime-TMk0lGuy.js → targets-runtime-RBjx3pg_.js} +1 -2
- package/dist/{text-runtime-CaKLhowd.js → text-runtime-DyfmcATV.js} +1 -1
- package/node_modules/baileys/lib/Defaults/index.js +1 -1
- package/node_modules/baileys/lib/Socket/business.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/chats.d.ts +1 -0
- package/node_modules/baileys/lib/Socket/chats.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/chats.js +10 -5
- package/node_modules/baileys/lib/Socket/chats.js.map +1 -1
- package/node_modules/baileys/lib/Socket/communities.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/groups.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/index.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/messages-recv.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/messages-send.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/newsletter.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/socket.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/socket.js +3 -0
- package/node_modules/baileys/lib/Socket/socket.js.map +1 -1
- package/node_modules/baileys/lib/Types/index.d.ts +1 -0
- package/node_modules/baileys/lib/Types/index.d.ts.map +1 -1
- package/node_modules/baileys/lib/Types/index.js.map +1 -1
- package/node_modules/baileys/lib/Utils/browser-utils.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/browser-utils.js +1 -0
- package/node_modules/baileys/lib/Utils/browser-utils.js.map +1 -1
- package/node_modules/baileys/lib/Utils/generics.d.ts +1 -0
- package/node_modules/baileys/lib/Utils/generics.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/generics.js +1 -1
- package/node_modules/baileys/lib/Utils/generics.js.map +1 -1
- package/node_modules/baileys/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/tc-token-utils.js +3 -2
- package/node_modules/baileys/lib/Utils/tc-token-utils.js.map +1 -1
- package/node_modules/baileys/lib/Utils/validate-connection.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/validate-connection.js +9 -2
- package/node_modules/baileys/lib/Utils/validate-connection.js.map +1 -1
- package/node_modules/baileys/node_modules/content-type/README.md +2 -0
- package/node_modules/baileys/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/baileys/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/baileys/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/baileys/node_modules/content-type/package.json +1 -1
- package/node_modules/baileys/node_modules/file-type/package.json +1 -1
- package/node_modules/baileys/node_modules/file-type/readme.md +3 -0
- package/node_modules/baileys/node_modules/file-type/source/detectors/zip.js +6 -1
- package/node_modules/baileys/node_modules/file-type/source/index.d.ts +3 -0
- package/node_modules/baileys/node_modules/file-type/source/index.js +25 -13
- package/node_modules/baileys/node_modules/music-metadata/LICENSE.txt +9 -9
- package/node_modules/baileys/node_modules/music-metadata/README.md +878 -878
- package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.d.ts +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.d.ts +1 -4
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.js +66 -30
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.d.ts +5 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.js +94 -25
- package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfChunk.js +2 -2
- package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfParser.js +38 -13
- package/node_modules/baileys/node_modules/music-metadata/lib/mp4/AtomToken.js +2 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/mp4/MP4Parser.js +34 -7
- package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.d.ts +7 -0
- package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.js +13 -0
- package/node_modules/baileys/node_modules/music-metadata/lib/riff/RiffChunk.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/package.json +156 -156
- package/node_modules/baileys/node_modules/process-warning/.github/dependabot.yml +42 -2
- package/node_modules/baileys/node_modules/process-warning/.github/workflows/ci.yml +12 -1
- package/node_modules/baileys/node_modules/process-warning/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/baileys/node_modules/process-warning/LICENSE +1 -1
- package/node_modules/baileys/node_modules/process-warning/README.md +41 -2
- package/node_modules/baileys/node_modules/process-warning/index.js +85 -17
- package/node_modules/baileys/node_modules/process-warning/package.json +6 -7
- package/node_modules/baileys/node_modules/process-warning/test/emit-once-only.test.js +3 -3
- package/node_modules/baileys/node_modules/process-warning/test/emit-reset.test.js +4 -4
- package/node_modules/baileys/node_modules/process-warning/test/emit-unlimited.test.js +2 -2
- package/node_modules/baileys/node_modules/process-warning/test/spy-warning.test.js +143 -0
- package/node_modules/baileys/node_modules/process-warning/types/index.d.ts +15 -1
- package/node_modules/baileys/node_modules/process-warning/types/index.tst.ts +48 -0
- package/node_modules/baileys/node_modules/protobufjs/README.md +61 -84
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js +66 -45
- 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 +47 -40
- 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 +92 -68
- 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.js +26 -10
- package/node_modules/baileys/node_modules/protobufjs/index.d.ts +3 -0
- package/node_modules/baileys/node_modules/protobufjs/package.json +1 -1
- package/node_modules/baileys/node_modules/protobufjs/src/converter.js +5 -1
- package/node_modules/baileys/node_modules/protobufjs/src/enum.js +5 -2
- package/node_modules/baileys/node_modules/protobufjs/src/field.js +6 -1
- package/node_modules/baileys/node_modules/protobufjs/src/parse.js +26 -23
- package/node_modules/baileys/node_modules/protobufjs/src/reader.js +36 -9
- package/node_modules/baileys/node_modules/protobufjs/src/util/codegen.js +3 -1
- package/node_modules/baileys/node_modules/protobufjs/src/util/utf8.js +2 -28
- package/node_modules/baileys/node_modules/protobufjs/src/writer.js +7 -1
- 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/baileys/package.json +1 -1
- package/node_modules/typebox/build/format/date.d.mts +1 -1
- package/node_modules/typebox/build/format/date.mjs +1 -1
- package/node_modules/typebox/build/format/date_time.d.mts +2 -2
- package/node_modules/typebox/build/format/date_time.mjs +3 -3
- package/node_modules/typebox/build/format/email.d.mts +1 -1
- package/node_modules/typebox/build/format/email.mjs +2 -2
- package/node_modules/typebox/build/format/hostname.mjs +2 -10
- package/node_modules/typebox/build/format/idn_email.d.mts +1 -1
- package/node_modules/typebox/build/format/idn_email.mjs +3 -3
- package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idn_hostname.mjs +3 -11
- package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
- package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
- package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
- package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
- package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
- package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/idn-hostname.mjs +41 -0
- package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
- package/node_modules/typebox/build/format/idna/index.mjs +2 -0
- package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
- package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
- package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
- package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
- package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
- package/node_modules/typebox/build/format/ipv4.d.mts +0 -1
- package/node_modules/typebox/build/format/ipv4.mjs +2 -32
- package/node_modules/typebox/build/format/ipv6.mjs +2 -61
- package/node_modules/typebox/build/format/iri.d.mts +2 -2
- package/node_modules/typebox/build/format/iri.mjs +26 -8
- package/node_modules/typebox/build/format/iri_reference.d.mts +2 -2
- package/node_modules/typebox/build/format/iri_reference.mjs +9 -55
- package/node_modules/typebox/build/format/regex.d.mts +1 -2
- package/node_modules/typebox/build/format/regex.mjs +2 -6
- package/node_modules/typebox/build/format/time.d.mts +2 -2
- package/node_modules/typebox/build/format/time.mjs +19 -14
- package/node_modules/typebox/build/format/uri.d.mts +1 -1
- package/node_modules/typebox/build/format/uri.mjs +3 -130
- package/node_modules/typebox/build/format/uri_reference.d.mts +1 -1
- package/node_modules/typebox/build/format/uri_reference.mjs +2 -3
- package/node_modules/typebox/build/format/uri_template.d.mts +2 -3
- package/node_modules/typebox/build/format/uri_template.mjs +4 -5
- package/node_modules/typebox/build/format/url.d.mts +3 -3
- package/node_modules/typebox/build/format/url.mjs +4 -5
- package/node_modules/typebox/build/guard/emit.d.mts +3 -1
- package/node_modules/typebox/build/guard/emit.mjs +12 -5
- package/node_modules/typebox/build/guard/guard.d.mts +8 -2
- package/node_modules/typebox/build/guard/guard.mjs +25 -4
- package/node_modules/typebox/build/guard/string.d.mts +2 -2
- package/node_modules/typebox/build/guard/string.mjs +7 -7
- package/node_modules/typebox/build/schema/engine/_context.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -2
- package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
- package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
- package/node_modules/typebox/build/schema/engine/_stack.mjs +12 -13
- package/node_modules/typebox/build/schema/engine/additionalItems.mjs +17 -7
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +4 -3
- package/node_modules/typebox/build/schema/engine/contains.mjs +18 -6
- package/node_modules/typebox/build/schema/engine/enum.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/items.mjs +26 -6
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/minContains.mjs +14 -4
- package/node_modules/typebox/build/schema/engine/not.mjs +4 -2
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +7 -6
- package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -2
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +4 -3
- package/node_modules/typebox/build/schema/engine/ref.mjs +1 -7
- package/node_modules/typebox/build/schema/engine/schema.mjs +13 -4
- package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
- package/node_modules/typebox/build/schema/resolve/resolve.d.mts +4 -1
- package/node_modules/typebox/build/schema/resolve/resolve.mjs +202 -1
- package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
- package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
- package/node_modules/typebox/build/schema/static/schema.d.mts +3 -0
- package/node_modules/typebox/build/schema/types/index.d.mts +0 -2
- package/node_modules/typebox/build/schema/types/index.mjs +0 -2
- package/node_modules/typebox/build/system/memory/clone.mjs +14 -11
- package/node_modules/typebox/build/system/memory/discard.mjs +6 -5
- package/node_modules/typebox/build/system/settings/settings.d.mts +9 -0
- package/node_modules/typebox/build/system/settings/settings.mjs +2 -0
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +6 -1
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +16 -3
- package/node_modules/typebox/build/type/engine/call/instantiate.mjs +34 -4
- package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +5 -5
- package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +20 -26
- package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +6 -10
- package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +9 -13
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +7 -4
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +12 -19
- package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +4 -20
- package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +8 -20
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +4 -4
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +11 -8
- package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +3 -4
- package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +17 -2
- package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +26 -6
- package/node_modules/typebox/build/type/engine/exclude/operation.mjs +3 -4
- package/node_modules/typebox/build/type/engine/extract/operation.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/extract/operation.mjs +3 -4
- package/node_modules/typebox/build/type/engine/priority/priority.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/priority/priority.mjs +3 -4
- package/node_modules/typebox/build/type/script/mapping.d.mts +32 -29
- package/node_modules/typebox/build/type/script/mapping.mjs +18 -25
- package/node_modules/typebox/build/type/script/parser.d.mts +19 -25
- package/node_modules/typebox/build/type/script/parser.mjs +27 -23
- package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
- package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
- package/node_modules/typebox/package.json +27 -27
- package/node_modules/typebox/readme.md +79 -82
- package/openclaw.plugin.json +2 -1
- package/package.json +6 -6
- package/node_modules/baileys/node_modules/process-warning/types/index.test-d.ts +0 -36
- package/node_modules/typebox/build/format/_idna.d.mts +0 -2
- package/node_modules/typebox/build/format/_idna.mjs +0 -246
- package/node_modules/typebox/build/format/_puny.d.mts +0 -1
- package/node_modules/typebox/build/format/_puny.mjs +0 -77
- package/node_modules/typebox/build/schema/resolve/ref.d.mts +0 -3
- package/node_modules/typebox/build/schema/resolve/ref.mjs +0 -146
- package/node_modules/typebox/build/schema/types/contentEncoding.d.mts +0 -9
- package/node_modules/typebox/build/schema/types/contentEncoding.mjs +0 -13
- package/node_modules/typebox/build/schema/types/contentMediaType.d.mts +0 -9
- package/node_modules/typebox/build/schema/types/contentMediaType.mjs +0 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "process-warning",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "A small utility for creating warnings and emitting them.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test": "npm run test:unit && npm run test:jest && npm run test:typescript",
|
|
12
12
|
"test:jest": "jest jest.test.js",
|
|
13
13
|
"test:unit": "c8 --100 node --test",
|
|
14
|
-
"test:typescript": "
|
|
14
|
+
"test:typescript": "tstyche"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -62,12 +62,11 @@
|
|
|
62
62
|
}
|
|
63
63
|
],
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@fastify/pre-commit": "^2.1.0",
|
|
66
65
|
"benchmark": "^2.1.4",
|
|
67
|
-
"c8": "^
|
|
66
|
+
"c8": "^12.0.0",
|
|
68
67
|
"eslint": "^9.17.0",
|
|
69
|
-
"jest": "^
|
|
70
|
-
"neostandard": "^0.
|
|
71
|
-
"
|
|
68
|
+
"jest": "^30.0.3",
|
|
69
|
+
"neostandard": "^0.13.0",
|
|
70
|
+
"tstyche": "^7.0.0"
|
|
72
71
|
}
|
|
73
72
|
}
|
|
@@ -5,7 +5,7 @@ const { createWarning } = require('..')
|
|
|
5
5
|
const { withResolvers } = require('./promise')
|
|
6
6
|
|
|
7
7
|
test('emit should emit a given code only once', t => {
|
|
8
|
-
t.plan(
|
|
8
|
+
t.plan(6)
|
|
9
9
|
|
|
10
10
|
const { promise, resolve } = withResolvers()
|
|
11
11
|
|
|
@@ -22,8 +22,8 @@ test('emit should emit a given code only once', t => {
|
|
|
22
22
|
code: 'CODE',
|
|
23
23
|
message: 'Hello world'
|
|
24
24
|
})
|
|
25
|
-
warn()
|
|
26
|
-
warn()
|
|
25
|
+
t.assert.strictEqual(warn(), true)
|
|
26
|
+
t.assert.strictEqual(warn(), false)
|
|
27
27
|
setImmediate(() => {
|
|
28
28
|
process.removeListener('warning', onWarning)
|
|
29
29
|
resolve()
|
|
@@ -5,7 +5,7 @@ const { createWarning } = require('../')
|
|
|
5
5
|
const { withResolvers } = require('./promise')
|
|
6
6
|
|
|
7
7
|
test('a limited warning can be re-set', t => {
|
|
8
|
-
t.plan(
|
|
8
|
+
t.plan(7)
|
|
9
9
|
|
|
10
10
|
const { promise, resolve } = withResolvers()
|
|
11
11
|
let count = 0
|
|
@@ -20,14 +20,14 @@ test('a limited warning can be re-set', t => {
|
|
|
20
20
|
message: 'Hello world'
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
warn()
|
|
23
|
+
t.assert.strictEqual(warn(), true)
|
|
24
24
|
t.assert.ok(warn.emitted)
|
|
25
25
|
|
|
26
|
-
warn()
|
|
26
|
+
t.assert.strictEqual(warn(), false)
|
|
27
27
|
t.assert.ok(warn.emitted)
|
|
28
28
|
|
|
29
29
|
warn.emitted = false
|
|
30
|
-
warn()
|
|
30
|
+
t.assert.strictEqual(warn(), true)
|
|
31
31
|
t.assert.ok(warn.emitted)
|
|
32
32
|
|
|
33
33
|
setImmediate(() => {
|
|
@@ -5,7 +5,7 @@ const { createWarning } = require('..')
|
|
|
5
5
|
const { withResolvers } = require('./promise')
|
|
6
6
|
|
|
7
7
|
test('emit should emit a given code unlimited times', t => {
|
|
8
|
-
t.plan(
|
|
8
|
+
t.plan(60)
|
|
9
9
|
|
|
10
10
|
let runs = 0
|
|
11
11
|
const expectedRun = []
|
|
@@ -31,7 +31,7 @@ test('emit should emit a given code unlimited times', t => {
|
|
|
31
31
|
|
|
32
32
|
for (let i = 0; i < times; i++) {
|
|
33
33
|
expectedRun.push(i)
|
|
34
|
-
warn()
|
|
34
|
+
t.assert.strictEqual(warn(), true)
|
|
35
35
|
}
|
|
36
36
|
setImmediate(() => {
|
|
37
37
|
process.removeListener('warning', onWarning)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const { createWarning } = require('..')
|
|
5
|
+
const { spyWarning } = require('..')
|
|
6
|
+
|
|
7
|
+
test('Spy ProcessWarning - unlimited: false', t => {
|
|
8
|
+
const warning = createWarning({
|
|
9
|
+
name: 'Warning',
|
|
10
|
+
code: 'WRN',
|
|
11
|
+
message: 'Hello %s'
|
|
12
|
+
})
|
|
13
|
+
const spyData = spyWarning(warning)
|
|
14
|
+
|
|
15
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
16
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
17
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
18
|
+
|
|
19
|
+
warning('World')
|
|
20
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
21
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
22
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
23
|
+
t.assert.strictEqual(spyData.callCount(), 1)
|
|
24
|
+
|
|
25
|
+
warning('World')
|
|
26
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
27
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
28
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
29
|
+
t.assert.deepStrictEqual(spyData.calls[1].arguments, ['World'])
|
|
30
|
+
t.assert.strictEqual(spyData.calls[1].result, false)
|
|
31
|
+
t.assert.strictEqual(spyData.callCount(), 2)
|
|
32
|
+
|
|
33
|
+
spyData.reset()
|
|
34
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
35
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
36
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
37
|
+
|
|
38
|
+
warning('World')
|
|
39
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
40
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
41
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
42
|
+
t.assert.strictEqual(spyData.callCount(), 1)
|
|
43
|
+
|
|
44
|
+
spyData.restore()
|
|
45
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
46
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
47
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
48
|
+
|
|
49
|
+
warning('World')
|
|
50
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
51
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
52
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('Spy ProcessWarning - unlimited: true', t => {
|
|
56
|
+
const warning = createWarning({
|
|
57
|
+
name: 'Warning',
|
|
58
|
+
code: 'WRN',
|
|
59
|
+
message: 'Hello %s',
|
|
60
|
+
unlimited: true
|
|
61
|
+
})
|
|
62
|
+
const spyData = spyWarning(warning)
|
|
63
|
+
|
|
64
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
65
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
66
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
67
|
+
|
|
68
|
+
warning('World')
|
|
69
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
70
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
71
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
72
|
+
t.assert.strictEqual(spyData.callCount(), 1)
|
|
73
|
+
|
|
74
|
+
warning('World')
|
|
75
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
76
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
77
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
78
|
+
t.assert.deepStrictEqual(spyData.calls[1].arguments, ['World'])
|
|
79
|
+
t.assert.strictEqual(spyData.calls[1].result, true)
|
|
80
|
+
t.assert.strictEqual(spyData.callCount(), 2)
|
|
81
|
+
|
|
82
|
+
spyData.reset()
|
|
83
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
84
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
85
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
86
|
+
|
|
87
|
+
warning('World')
|
|
88
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
89
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
90
|
+
t.assert.strictEqual(spyData.calls[0].result, true)
|
|
91
|
+
t.assert.strictEqual(spyData.callCount(), 1)
|
|
92
|
+
|
|
93
|
+
spyData.restore()
|
|
94
|
+
t.assert.strictEqual(warning.emitted, false)
|
|
95
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
96
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
97
|
+
|
|
98
|
+
warning('World')
|
|
99
|
+
t.assert.strictEqual(warning.emitted, true)
|
|
100
|
+
t.assert.deepStrictEqual(spyData.calls, [])
|
|
101
|
+
t.assert.strictEqual(spyData.callCount(), 0)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('Spy ProcessWarning - calls[].arguments', t => {
|
|
105
|
+
const warning = createWarning({
|
|
106
|
+
name: 'Warning',
|
|
107
|
+
code: 'WRN',
|
|
108
|
+
message: 'Hello %s'
|
|
109
|
+
})
|
|
110
|
+
const spyData = spyWarning(warning)
|
|
111
|
+
|
|
112
|
+
warning(undefined)
|
|
113
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, [])
|
|
114
|
+
spyData.reset()
|
|
115
|
+
|
|
116
|
+
warning()
|
|
117
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, [])
|
|
118
|
+
spyData.reset()
|
|
119
|
+
|
|
120
|
+
warning('World')
|
|
121
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World'])
|
|
122
|
+
spyData.reset()
|
|
123
|
+
|
|
124
|
+
warning('World', 'Hello')
|
|
125
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World', 'Hello'])
|
|
126
|
+
spyData.reset()
|
|
127
|
+
|
|
128
|
+
warning(undefined, 'Hello')
|
|
129
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, [undefined, 'Hello'])
|
|
130
|
+
spyData.reset()
|
|
131
|
+
|
|
132
|
+
warning('World', 'Hello', 'World')
|
|
133
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World', 'Hello', 'World'])
|
|
134
|
+
spyData.reset()
|
|
135
|
+
|
|
136
|
+
warning('World', undefined, 'World')
|
|
137
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, ['World', undefined, 'World'])
|
|
138
|
+
spyData.reset()
|
|
139
|
+
|
|
140
|
+
warning(undefined, 'Hello', 'World')
|
|
141
|
+
t.assert.deepStrictEqual(spyData.calls[0].arguments, [undefined, 'Hello', 'World'])
|
|
142
|
+
spyData.reset()
|
|
143
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare namespace processWarning {
|
|
2
2
|
export interface WarningItem {
|
|
3
|
-
(a?: any, b?: any, c?: any):
|
|
3
|
+
(a?: any, b?: any, c?: any): boolean;
|
|
4
4
|
name: string;
|
|
5
5
|
code: string;
|
|
6
6
|
message: string;
|
|
@@ -22,13 +22,27 @@ declare namespace processWarning {
|
|
|
22
22
|
unlimited?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
export type WarningSpyData = {
|
|
26
|
+
calls: WarningCallData[],
|
|
27
|
+
callCount(): number
|
|
28
|
+
reset(): void
|
|
29
|
+
restore(): void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type WarningCallData = {
|
|
33
|
+
arguments: unknown[]
|
|
34
|
+
result: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
export type ProcessWarning = {
|
|
26
38
|
createWarning(params: WarningOptions): WarningItem;
|
|
27
39
|
createDeprecation(params: DeprecationOptions): WarningItem;
|
|
40
|
+
spyWarning(warning: WarningItem): WarningSpyData
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export function createWarning (params: WarningOptions): WarningItem
|
|
31
44
|
export function createDeprecation (params: DeprecationOptions): WarningItem
|
|
45
|
+
export function spyWarning (warning: WarningItem): WarningSpyData
|
|
32
46
|
|
|
33
47
|
const processWarning: ProcessWarning
|
|
34
48
|
export { processWarning as default }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { expect } from 'tstyche'
|
|
2
|
+
import { createDeprecation, createWarning, spyWarning, WarningCallData, WarningSpyData } from '..'
|
|
3
|
+
|
|
4
|
+
const WarnInstance = createWarning({
|
|
5
|
+
name: 'TypeScriptWarning',
|
|
6
|
+
code: 'CODE',
|
|
7
|
+
message: 'message'
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
expect(WarnInstance.code).type.toBe<string>()
|
|
11
|
+
expect(WarnInstance.message).type.toBe<string>()
|
|
12
|
+
expect(WarnInstance.name).type.toBe<string>()
|
|
13
|
+
expect(WarnInstance.emitted).type.toBe<boolean>()
|
|
14
|
+
expect(WarnInstance.unlimited).type.toBe<boolean>()
|
|
15
|
+
|
|
16
|
+
expect(WarnInstance()).type.toBe<boolean>()
|
|
17
|
+
expect(WarnInstance('foo')).type.toBe<boolean>()
|
|
18
|
+
expect(WarnInstance('foo', 'bar')).type.toBe<boolean>()
|
|
19
|
+
|
|
20
|
+
const buildWarnUnlimited = createWarning({
|
|
21
|
+
name: 'TypeScriptWarning',
|
|
22
|
+
code: 'CODE',
|
|
23
|
+
message: 'message',
|
|
24
|
+
unlimited: true
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
expect(buildWarnUnlimited.unlimited).type.toBe<boolean>()
|
|
28
|
+
|
|
29
|
+
const DeprecationInstance = createDeprecation({
|
|
30
|
+
code: 'CODE',
|
|
31
|
+
message: 'message'
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
expect(DeprecationInstance.code).type.toBe<string>()
|
|
35
|
+
|
|
36
|
+
expect(DeprecationInstance()).type.toBe<boolean>()
|
|
37
|
+
expect(DeprecationInstance('foo')).type.toBe<boolean>()
|
|
38
|
+
expect(DeprecationInstance('foo', 'bar')).type.toBe<boolean>()
|
|
39
|
+
|
|
40
|
+
const spyData = spyWarning(WarnInstance)
|
|
41
|
+
expect(spyData).type.toBe<WarningSpyData>()
|
|
42
|
+
expect(spyData.calls).type.toBe<WarningCallData[]>()
|
|
43
|
+
expect(spyData.callCount).type.toBe<(() => number)>()
|
|
44
|
+
expect(spyData.callCount()).type.toBe<number>()
|
|
45
|
+
expect(spyData.reset).type.toBe<(() => void)>()
|
|
46
|
+
expect(spyData.reset()).type.toBe<void>()
|
|
47
|
+
expect(spyData.restore).type.toBe<(() => void)>()
|
|
48
|
+
expect(spyData.restore()).type.toBe<void>()
|
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
<a href="https://www.jsdelivr.com/package/npm/protobufjs"><img src="https://img.shields.io/jsdelivr/npm/hm/protobufjs?label=requests&logo=jsdelivr" alt=""></a>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
-
**
|
|
11
|
-
|
|
12
|
-
**protobuf.js** is a very fast, conformant, and unusually versatile JavaScript implementation of Protocol Buffers for Node.js and browsers. It works with `.proto` files out of the box, does not require protoc, and supports runtime reflection as well as specialized code generation with strong TypeScript declarations.
|
|
10
|
+
**protobuf.js** is a very fast, conformant, and unusually versatile JavaScript implementation of [Protocol Buffers](https://protobuf.dev) for Node.js and browsers. It is independently maintained with contributions from the upstream Protocol Buffers project, works with `.proto` schemas without requiring `protoc`, and supports runtime reflection as well as specialized code generation with matching TypeScript declarations.
|
|
13
11
|
|
|
14
12
|
If protobuf.js is important to your project or organization, or if you depend on it commercially, [consider supporting](https://github.com/sponsors/dcodeIO) its ongoing maintenance. Sponsorship helps make bug fixes, releases, LTS/security handling, and user support more sustainable.
|
|
15
13
|
|
|
16
14
|
## Getting started
|
|
17
15
|
|
|
18
|
-
Getting up and running is simple: Install the package, load a
|
|
16
|
+
Getting up and running is simple: Install the package, load a schema, and you are all set to encode and decode Protobuf messages. From there, protobuf.js grows with your requirements: Add code generation with TypeScript declarations, transport-agnostic services, support for text-based formats, and more as needed.
|
|
19
17
|
|
|
20
18
|
### Install
|
|
21
19
|
|
|
@@ -33,7 +31,7 @@ The CLI is a JS-native protobuf.js toolchain that does not require setting up `p
|
|
|
33
31
|
|
|
34
32
|
#### Browser builds
|
|
35
33
|
|
|
36
|
-
Canonical browser builds
|
|
34
|
+
Canonical browser builds are [provided via the jsDelivr CDN](https://cdn.jsdelivr.net/npm/protobufjs@8.X.X/dist/), supporting CommonJS, AMD and global `window.protobuf`. Make sure to pin an exact version in production.
|
|
37
35
|
|
|
38
36
|
## Usage
|
|
39
37
|
|
|
@@ -78,7 +76,7 @@ const decoded = AwesomeMessage.decode(encoded);
|
|
|
78
76
|
|
|
79
77
|
Plain objects can be encoded directly when they already use protobuf.js runtime types: numbers for 32-bit numeric fields, booleans for `bool`, strings for `string`, `Uint8Array` or `Buffer` for `bytes`, arrays for repeated fields, and plain objects for maps. Map keys are the string representation of the respective value or an 8-character hash string for 64-bit keys.
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
Note that, as with any structured binary format, decoded structures incur runtime memory overhead beyond their encoded representation. Applications processing untrusted input should therefore apply appropriate input-size and concurrency limits to bound memory use. For this reason, unknown fields present on the wire are intentionally discarded as the safer default, but can be retained by setting `reader.discardUnknown = false` per reader, or by setting `Reader.discardUnknown = false` to make it the default for subsequently created readers. Preserved unknown field data can also be explicitly dropped with `delete message.$unknowns`.
|
|
82
80
|
|
|
83
81
|
### Convert plain objects
|
|
84
82
|
|
|
@@ -138,41 +136,28 @@ Message types expose focused methods for validation, conversion, and binary I/O.
|
|
|
138
136
|
* **message.toJSON**(): `object`
|
|
139
137
|
Converts a message instance to JSON-compatible output using default conversion options.
|
|
140
138
|
|
|
141
|
-
Message instances provide runtime identity
|
|
139
|
+
Message instances provide stable runtime identity for testing with `instanceof`.
|
|
142
140
|
|
|
143
141
|
Length-delimited methods read and write a varint byte length before the message, which is useful for streams and framed protocols.
|
|
144
142
|
|
|
145
143
|
If required fields are missing while decoding proto2 data, `decode` throws `protobuf.util.ProtocolError` with the partially decoded message available as `err.instance`.
|
|
146
144
|
|
|
147
|
-
## Runtimes
|
|
148
|
-
|
|
149
|
-
protobuf.js provides three runtime entry points, keeping parser and reflection support optional: Runtime `.proto` loading needs the parser, JSON/reflection bundles need reflection support, and generated static modules only need the minimal runtime.
|
|
150
|
-
|
|
151
|
-
| Import | Includes | Use when
|
|
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
|
|
156
|
-
|
|
157
|
-
The full build includes the light build, and the light build includes the minimal runtime.
|
|
158
|
-
|
|
159
145
|
## Code generation
|
|
160
146
|
|
|
161
|
-
Use [`protobufjs-cli`](./cli/#readme) to generate
|
|
147
|
+
Use [`protobufjs-cli`](./cli/#readme) to generate schema-specific code, either directly with `pbjs` or through the optional `protoc-gen-pbjs` plugin for `protoc`.
|
|
162
148
|
|
|
163
|
-
|
|
149
|
+
protobuf.js offers two code-generation modes, both with matching TypeScript declarations: reflection modules generate optimized code at runtime with reflection metadata retained; static modules generate reflection-free code ahead of time. Both use the same runtime package and automatically import only the runtime capabilities they need.
|
|
164
150
|
|
|
165
|
-
| Target | Output |
|
|
166
|
-
|
|
167
|
-
| `json` |
|
|
168
|
-
| `
|
|
169
|
-
| `static-module` | Static code module | `protobufjs/minimal.js` |
|
|
151
|
+
| Target | Output | Runtime entry |
|
|
152
|
+
|--------|--------|---------------|
|
|
153
|
+
| `json-module` | Reflection module | `protobufjs/light.js` (without parser) |
|
|
154
|
+
| `static-module` | Static code module | `protobufjs/minimal.js` (without reflection) |
|
|
170
155
|
|
|
171
156
|
Module targets support `--wrap default` for CommonJS and AMD, plus `esm`, `commonjs`, `amd`, and `closure`; `--wrap` can also load a custom wrapper module.
|
|
172
157
|
|
|
173
158
|
### Static modules
|
|
174
159
|
|
|
175
|
-
Static modules emit dedicated JavaScript for your schema
|
|
160
|
+
Static modules emit dedicated, reflection-free JavaScript code for your schema.
|
|
176
161
|
|
|
177
162
|
```sh
|
|
178
163
|
npx pbjs -t static-module -w esm -o awesome.js --dts awesome.proto
|
|
@@ -184,22 +169,11 @@ import { awesomepackage } from "./awesome.js";
|
|
|
184
169
|
const message = awesomepackage.AwesomeMessage.create({ awesomeField: "hello" });
|
|
185
170
|
```
|
|
186
171
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
### Reflection bundles
|
|
172
|
+
Static code is repetitive by design, but compresses unusually well with Brotli or gzip and works in [CSP](https://w3c.github.io/webappsec-csp/)-restricted environments.
|
|
190
173
|
|
|
191
|
-
Reflection
|
|
174
|
+
### Reflection modules
|
|
192
175
|
|
|
193
|
-
|
|
194
|
-
npx pbjs -t json -o awesome.json awesome1.proto awesome2.proto ...
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
const bundle = require("./awesome.json");
|
|
199
|
-
|
|
200
|
-
const root = protobuf.Root.fromJSON(bundle);
|
|
201
|
-
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
202
|
-
```
|
|
176
|
+
Reflection modules wrap schemas as compact JSON metadata while avoiding `.proto` parsing at runtime.
|
|
203
177
|
|
|
204
178
|
```sh
|
|
205
179
|
npx pbjs -t json-module -w esm -o awesome.js --dts awesome.proto
|
|
@@ -211,13 +185,11 @@ import { awesomepackage } from "./awesome.js";
|
|
|
211
185
|
const AwesomeMessage = awesomepackage.AwesomeMessage;
|
|
212
186
|
```
|
|
213
187
|
|
|
214
|
-
|
|
188
|
+
Declarations for reflection modules mirror `static-module` typings. Because JSON modules export reflection objects, message instances should be created with `MyMessage.create(...)` rather than constructors. Code using `create(...)` works with static modules as well. Separately, `-t json` can serialize reflection metadata as bare JSON bundles for use with `load()` or `Root.fromJSON()`.
|
|
215
189
|
|
|
216
190
|
### TypeScript integration
|
|
217
191
|
|
|
218
|
-
protobuf.js works with TypeScript out of the box:
|
|
219
|
-
|
|
220
|
-
For example, given the oneof:
|
|
192
|
+
protobuf.js works with TypeScript out of the box: its runtime API is typed, and generated code can be paired with matching TypeScript declarations in a single CLI invocation. Declarations are strongly typed, including discriminated unions for oneofs and scoped types for plain-object usage:
|
|
221
193
|
|
|
222
194
|
```proto
|
|
223
195
|
message Profile {
|
|
@@ -228,8 +200,6 @@ message Profile {
|
|
|
228
200
|
}
|
|
229
201
|
```
|
|
230
202
|
|
|
231
|
-
Generated declarations narrow both the `contact` oneof and the concrete values:
|
|
232
|
-
|
|
233
203
|
```ts
|
|
234
204
|
const profile = Profile.create({
|
|
235
205
|
contact: "email",
|
|
@@ -246,7 +216,7 @@ if (decoded.contact === "phone") {
|
|
|
246
216
|
}
|
|
247
217
|
```
|
|
248
218
|
|
|
249
|
-
|
|
219
|
+
The same narrowed shape is available for plain-object inputs:
|
|
250
220
|
|
|
251
221
|
```ts
|
|
252
222
|
const object: Profile.$Shape = {
|
|
@@ -259,7 +229,7 @@ const object: Profile.$Shape = {
|
|
|
259
229
|
|
|
260
230
|
### Programmatic schemas
|
|
261
231
|
|
|
262
|
-
|
|
232
|
+
Schemas can be constructed directly through reflection:
|
|
263
233
|
|
|
264
234
|
```ts
|
|
265
235
|
const AwesomeMessage = new protobuf.Type("AwesomeMessage")
|
|
@@ -316,22 +286,7 @@ const myService = MyService.create(myRpcImpl/*, requestDelimited?, responseDelim
|
|
|
316
286
|
|
|
317
287
|
See [examples/streaming-rpc.js](./examples/streaming-rpc.js) for a streaming example.
|
|
318
288
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
```js
|
|
322
|
-
const grpc = require('@grpc/grpc-js');
|
|
323
|
-
|
|
324
|
-
const Client = grpc.makeGenericClientConstructor({});
|
|
325
|
-
const client = new Client(serverAddress, grpc.credentials.createInsecure());
|
|
326
|
-
|
|
327
|
-
const rpcImpl = (method, requestData, callback) =>
|
|
328
|
-
client.makeUnaryRequest(method.path, (data) => data, (data) => data, requestData, callback);
|
|
329
|
-
|
|
330
|
-
const greeter = root.lookupService("example.Greeter").create(rpcImpl);
|
|
331
|
-
const reply = await greeter.sayHello({ name: "world" });
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
See [examples/grpc-service.js](./examples/grpc-service.js) for a complete example.
|
|
289
|
+
See [examples/grpc-service.js](./examples/grpc-service.js) for an integration example with [@grpc/grpc-js](https://www.npmjs.com/package/@grpc/grpc-js).
|
|
335
290
|
|
|
336
291
|
### Extensions
|
|
337
292
|
|
|
@@ -339,7 +294,7 @@ The following extensions provide descriptor conversion and text-based protobuf f
|
|
|
339
294
|
|
|
340
295
|
#### Descriptors
|
|
341
296
|
|
|
342
|
-
protobuf.js uses a compact JSON-based reflection representation internally
|
|
297
|
+
protobuf.js uses a compact JSON-based reflection representation internally. See [ext/descriptor](./ext/README.md#descriptor) for use cases that need conversion between reflected roots and `protoc` descriptor messages.
|
|
343
298
|
|
|
344
299
|
#### ProtoJSON
|
|
345
300
|
|
|
@@ -351,7 +306,7 @@ Protocol Buffers [Text Format](https://protobuf.dev/reference/protobuf/textforma
|
|
|
351
306
|
|
|
352
307
|
## Conformance
|
|
353
308
|
|
|
354
|
-
protobuf.js is validated against the official Protocol Buffers conformance suite
|
|
309
|
+
protobuf.js is validated against the official Protocol Buffers conformance suite. It passes all required and recommended tests for the **Proto2**, **Proto3** and **Editions** binary wire formats, with complete **ProtoJSON** and **Text Format** support available as optional extensions when those formats are needed.
|
|
355
310
|
|
|
356
311
|
<!-- BEGIN CONFORMANCE DATA -->
|
|
357
312
|
|
|
@@ -367,37 +322,59 @@ protobuf.js is validated against the official Protocol Buffers conformance suite
|
|
|
367
322
|
|
|
368
323
|
<!-- END CONFORMANCE DATA -->
|
|
369
324
|
|
|
370
|
-
[Structured results](https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml?query=branch%3Amaster+event%3Apush) are available as CI artifacts.
|
|
325
|
+
[Structured results](https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml?query=branch%3Amaster+event%3Apush) of the conformance tests are also available as CI artifacts.
|
|
371
326
|
|
|
372
327
|
## Performance
|
|
373
328
|
|
|
374
|
-
|
|
329
|
+
Both reflection and static modes use specialized encoders and decoders backed by the same hand-tuned reader and writer primitives.
|
|
375
330
|
|
|
376
|
-
The repository includes a [
|
|
331
|
+
The repository includes a [benchmark suite](./bench) you can run yourself. It compares protobuf.js with other general-purpose JavaScript implementations across three substantially different cases: our classic common message shape and two unmodified, structurally distinct fixtures sourced externally. The suite measures each library's recommended serialization and deserialization path using identical schemas and inputs, with JSON included as an additional baseline. Across these cases, protobuf.js is a clear upgrade over using JSON and consistently the fastest Protobuf implementation by a considerable margin.
|
|
377
332
|
|
|
378
333
|
<!-- BEGIN BENCHMARK DATA -->
|
|
379
334
|
|
|
380
|
-
|
|
335
|
+
<picture>
|
|
336
|
+
<source media="(prefers-color-scheme: dark)" srcset="./bench/results/encode-dark.svg">
|
|
337
|
+
<source media="(prefers-color-scheme: light)" srcset="./bench/results/encode-light.svg">
|
|
338
|
+
<img alt="Encode benchmark" src="./bench/results/encode.svg">
|
|
339
|
+
</picture>
|
|
340
|
+
|
|
341
|
+
<details>
|
|
342
|
+
<summary>Show table</summary>
|
|
343
|
+
|
|
344
|
+
| Implementation | Common | Vector tile | Buf perf |
|
|
345
|
+
| --- | ---: | ---: | ---: |
|
|
346
|
+
| protobuf.js static | **5.34M ops/s** <small>1.0x</small> | **3.09K ops/s** <small>1.0x</small> | 43.1K ops/s <small>1.0x</small> |
|
|
347
|
+
| protobuf.js reflect | 4.89M ops/s <small>1.1x</small> | 3.03K ops/s <small>1.0x</small> | **43.3K ops/s** <small>1.0x</small> |
|
|
348
|
+
| JSON | 2.09M ops/s <small>2.6x</small> | 897 ops/s <small>3.4x</small> | 6.70K ops/s <small>6.5x</small> |
|
|
349
|
+
| protoc-gen-js | 1.03M ops/s <small>5.2x</small> | 700 ops/s <small>4.4x</small> | 13.9K ops/s <small>3.1x</small> |
|
|
350
|
+
| protoc-gen-es | 402K ops/s <small>13.3x</small> | 235 ops/s <small>13.2x</small> | 8.22K ops/s <small>5.3x</small> |
|
|
351
|
+
|
|
352
|
+
</details>
|
|
353
|
+
|
|
354
|
+
<picture>
|
|
355
|
+
<source media="(prefers-color-scheme: dark)" srcset="./bench/results/decode-dark.svg">
|
|
356
|
+
<source media="(prefers-color-scheme: light)" srcset="./bench/results/decode-light.svg">
|
|
357
|
+
<img alt="Decode benchmark" src="./bench/results/decode.svg">
|
|
358
|
+
</picture>
|
|
381
359
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
| Common | 3.18M ops/s | 3.25M ops/s | 2.07M ops/s | 1.01M ops/s | 395K ops/s |
|
|
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 |
|
|
360
|
+
<details>
|
|
361
|
+
<summary>Show table</summary>
|
|
387
362
|
|
|
388
|
-
|
|
363
|
+
| Implementation | Common | Vector tile | Buf perf |
|
|
364
|
+
| --- | ---: | ---: | ---: |
|
|
365
|
+
| protobuf.js static | 6.45M ops/s <small>1.1x</small> | 2.70K ops/s <small>1.1x</small> | **81.7K ops/s** <small>1.0x</small> |
|
|
366
|
+
| protobuf.js reflect | **6.93M ops/s** <small>1.0x</small> | **2.99K ops/s** <small>1.0x</small> | 80.3K ops/s <small>1.0x</small> |
|
|
367
|
+
| JSON | 1.37M ops/s <small>5.0x</small> | 1.06K ops/s <small>2.8x</small> | 19.5K ops/s <small>4.2x</small> |
|
|
368
|
+
| protoc-gen-js | 811K ops/s <small>8.5x</small> | 851 ops/s <small>3.5x</small> | 21.7K ops/s <small>3.8x</small> |
|
|
369
|
+
| protoc-gen-es | 691K ops/s <small>10.0x</small> | 376 ops/s <small>8.0x</small> | 14.3K ops/s <small>5.7x</small> |
|
|
389
370
|
|
|
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 |
|
|
371
|
+
</details>
|
|
395
372
|
|
|
396
373
|
<!-- END BENCHMARK DATA -->
|
|
397
374
|
|
|
398
|
-
[Structured results](./bench/results/latest.json)
|
|
375
|
+
[Structured results](./bench/results/latest.json) and environment details for this run are also available as committed artifacts.
|
|
399
376
|
|
|
400
|
-
To run the benchmark
|
|
377
|
+
To run the benchmark on your own hardware:
|
|
401
378
|
|
|
402
379
|
```sh
|
|
403
380
|
npm --prefix bench install
|