msgpack5 6.0.1 → 6.1.0
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/.github/workflows/ci.yml +15 -4
- package/AGENTS.md +26 -0
- package/README.md +11 -3
- package/SECURITY.md +16 -0
- package/dist/msgpack5.js +1760 -1111
- package/dist/msgpack5.min.js +1 -1
- package/example.js +6 -1
- package/index.js +16 -2
- package/lib/decoder.js +152 -28
- package/lib/encoder.js +22 -1
- package/lib/streams.js +18 -17
- package/package.json +1 -1
- package/test/4-bytes-length-maps.js +31 -0
- package/test/64-bits-signed-integers.js +21 -0
- package/test/collection-length-limits.js +64 -0
- package/test/compatibility-mode.js +33 -0
- package/test/max-depth.js +95 -0
- package/test/object-prototype-poisoning.js +50 -0
- package/test/reserved-byte.js +53 -0
- package/test/streams.js +78 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -8,11 +8,19 @@ jobs:
|
|
|
8
8
|
fail-fast: false
|
|
9
9
|
matrix:
|
|
10
10
|
os: [macOS-latest, windows-latest, ubuntu-latest]
|
|
11
|
-
node-version: [10, 12, 14, 16]
|
|
11
|
+
node-version: [10, 12, 14, 16, 18, 20, 22, 24, 26]
|
|
12
|
+
exclude:
|
|
13
|
+
# These releases do not provide binaries for current arm64 macOS runners.
|
|
14
|
+
- os: macOS-latest
|
|
15
|
+
node-version: 10
|
|
16
|
+
- os: macOS-latest
|
|
17
|
+
node-version: 12
|
|
18
|
+
- os: macOS-latest
|
|
19
|
+
node-version: 14
|
|
12
20
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@v7
|
|
14
22
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
15
|
-
uses: actions/setup-node@
|
|
23
|
+
uses: actions/setup-node@v7
|
|
16
24
|
with:
|
|
17
25
|
node-version: ${{ matrix.node-version }}
|
|
18
26
|
- name: Install
|
|
@@ -23,8 +31,11 @@ jobs:
|
|
|
23
31
|
automerge:
|
|
24
32
|
needs: test
|
|
25
33
|
runs-on: ubuntu-latest
|
|
34
|
+
permissions:
|
|
35
|
+
contents: write
|
|
36
|
+
pull-requests: write
|
|
26
37
|
steps:
|
|
27
|
-
- uses: fastify/github-action-merge-dependabot@
|
|
38
|
+
- uses: fastify/github-action-merge-dependabot@v3
|
|
28
39
|
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
|
|
29
40
|
with:
|
|
30
41
|
github-token: ${{secrets.github_token}}
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
This file provides guidance to AI coding agents like Claude Code (claude.ai/code), Cursor AI, Codex, Gemini CLI, GitHub Copilot, and other AI coding assistants when working with code in this repository.
|
|
2
|
+
|
|
3
|
+
# Development commands
|
|
4
|
+
|
|
5
|
+
- Install dependencies: `npm install` (the repository has no lockfile).
|
|
6
|
+
- Run lint and the complete Tape suite: `npm test`.
|
|
7
|
+
- Run lint only: `./node_modules/.bin/standard`.
|
|
8
|
+
- Run one test file: `node test/streams.js` (replace the path with any `test/*.js` file). This emits raw TAP and does not run lint.
|
|
9
|
+
- Build both tracked browser bundles: `npm run build`. This runs Browserify for `dist/msgpack5.js`, then UglifyJS for `dist/msgpack5.min.js`.
|
|
10
|
+
- Build only the unminified browser bundle: `npm run browserify`; minify the existing bundle: `npm run dist`.
|
|
11
|
+
|
|
12
|
+
CI runs `npm test` on Node.js 10, 12, 14, 16, 18, 20, 22, 24, and 26. Node.js 10–14 run on Linux and Windows only because they do not provide binaries for current arm64 macOS runners; newer versions also run on macOS. Keep runtime code compatible with Node.js 10 unless the support matrix is intentionally changed.
|
|
13
|
+
|
|
14
|
+
# Architecture
|
|
15
|
+
|
|
16
|
+
- `index.js` is the CommonJS entry point and instance factory. Each `msgpack()` call creates private encoder and decoder extension registries, installs the timestamp codec, builds bound `encode`/`decode` functions, and exposes stream constructors plus the LevelUP encoding metadata.
|
|
17
|
+
- `lib/encoder.js` recursively dispatches JavaScript values to MessagePack wire families and returns a sliced `Buffer` at the public boundary. Maps and plain objects take separate paths; options such as `forceFloat64`, `sortKeys`, `compatibilityMode`, and `preferMap` alter wire-format decisions.
|
|
18
|
+
- `lib/decoder.js` is a recursive parser whose internal operations return `[value, consumedByteCount]` or `null` for incomplete input. Public `decode()` converts input to a `bl` BufferList, consumes exactly one value, and turns incomplete input into `IncompleteBufferError`.
|
|
19
|
+
- `lib/streams.js` depends on that decoder contract: it accumulates chunks, retains incomplete frames, and repeatedly decodes concatenated frames. The exported constructors rely on being called as `pack.encoder()` / `pack.decoder()` so `this` is the msgpack instance. `wrap: true` is required when stream values may be `null`.
|
|
20
|
+
- Extension encoders produce a buffer whose first byte is the signed extension type and whose remaining bytes are payload. `register()` adds this byte automatically; callers of the lower-level `registerEncoder()` must add it themselves and pair it with `registerDecoder()`. The built-in `lib/codecs/DateCodec.js` uses reserved type `-1`; `disableTimestampEncoding` disables only Date encoding, not decoding.
|
|
21
|
+
- Map decoding produces a plain object only when every key is a string and `preferMap` is false; otherwise it produces a `Map`. The `protoAction` handling applies during the plain-object path.
|
|
22
|
+
- `dist/` contains generated, committed standalone browser artifacts, not source. Regenerate both files with `npm run build` when source behavior exposed in the browser bundle changes.
|
|
23
|
+
|
|
24
|
+
# Test organization
|
|
25
|
+
|
|
26
|
+
Tests are Tape files grouped primarily by MessagePack wire type and size boundary. For encoder/decoder changes, preserve exact-byte assertions and cover both sides of affected boundaries; use the focused suites for extensions, timestamps, maps, prototype handling, and streaming when those cross-cutting paths change. `spec.md` is the checked-in MessagePack specification used by this implementation.
|
package/README.md
CHANGED
|
@@ -22,8 +22,13 @@ var msgpack = require('msgpack5')() // namespace our extensions
|
|
|
22
22
|
|
|
23
23
|
msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const hex = encode({ 'hello': 'world' }).toString('hex')
|
|
26
|
+
console.log(hex)
|
|
26
27
|
// 81a568656c6c6fa5776f726c64
|
|
28
|
+
const obj = decode(Buffer.from(hex, 'hex'))
|
|
29
|
+
console.log(obj)
|
|
30
|
+
// { hello: 'world' }
|
|
31
|
+
|
|
27
32
|
console.log(decode(encode({ 'hello': 'world' })))
|
|
28
33
|
// { hello: 'world' }
|
|
29
34
|
console.log(encode(a).toString('hex'))
|
|
@@ -108,10 +113,13 @@ options:
|
|
|
108
113
|
|
|
109
114
|
- `forceFloat64`, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults to false.
|
|
110
115
|
- `sortKeys`, a boolean to force a determinate keys order
|
|
111
|
-
- `compatibilityMode`, a boolean that enables "compatibility mode" which doesn't use str 8 format. Defaults to false.
|
|
116
|
+
- `compatibilityMode`, a boolean that enables "compatibility mode" which doesn't use bin format family and str 8 format. Defaults to false.
|
|
112
117
|
- `disableTimestampEncoding`, a boolean that when set disables the encoding of Dates into the [timestamp extension type](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type). Defaults to false.
|
|
113
118
|
- `preferMap`, a boolean that forces all maps to be decoded to `Map`s rather than plain objects. This ensures that `decode(encode(new Map())) instanceof Map` and that iteration order is preserved. Defaults to false.
|
|
114
|
-
- `
|
|
119
|
+
- `maxArrayLength`, a non-negative integer that limits the number of elements in a decoded array. Arrays over the limit throw a `RangeError`. Defaults to no limit beyond the MessagePack format maximum.
|
|
120
|
+
- `maxMapLength`, a non-negative integer that limits the number of entries in a decoded map. Maps over the limit throw a `RangeError`. Defaults to no limit beyond the MessagePack format maximum.
|
|
121
|
+
- `maxDepth`, a non-negative integer that limits how deeply arrays and maps can be nested when decoding. Defaults to 100.
|
|
122
|
+
- `protoAction`, a string which can be `error|ignore|remove` that determines what happens when decoding a plain object with a `__proto__` property which would cause prototype poisoning. `error` (the default when omitted) throws an error, `remove` removes the property, `ignore` (not recommended) allows the property, thereby causing prototype poisoning on the decoded object. Any other value throws a `TypeError`.
|
|
115
123
|
|
|
116
124
|
-------------------------------------------------------
|
|
117
125
|
<a name="encode"></a>
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 6.x.x | :white_check_mark: |
|
|
8
|
+
| 5.x.x | :white_check_mark: |
|
|
9
|
+
| 4.x.x | :white_check_mark: |
|
|
10
|
+
| 3.x.x | :white_check_mark: |
|
|
11
|
+
| 2.x.x | :x: |
|
|
12
|
+
| 1.x.x | :x: |
|
|
13
|
+
|
|
14
|
+
## Reporting a Vulnerability
|
|
15
|
+
|
|
16
|
+
Please report all vulnerabilities to [https://github.com/mcollina/msgpack5/security](https://github.com/mcollina/msgpack5/security).
|