Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx authored Jan 26, 2025
2 parents 2796aef + 0bb101d commit c7e0d03
Show file tree
Hide file tree
Showing 18 changed files with 2,524 additions and 1,215 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

89 changes: 0 additions & 89 deletions .eslintrc.js

This file was deleted.

20 changes: 12 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ jobs:
strategy:
matrix:
node-version:
- '16'
- '18'
- '20'
- '22'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ matrix.node-version }}

- run: npm install -g nyc codecov
- run: npm install -g nyc
- run: npm ci
- run: npm run test:cover
- run: codecov -f coverage/*.json

- uses: codecov/codecov-action@v5
with:
files: coverage/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }}

browser:
runs-on: ubuntu-latest
Expand All @@ -37,12 +41,12 @@ jobs:
browser: [ChromeHeadless, FirefoxHeadless]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
cache: npm
node-version: '18'
node-version: '22'
- run: npm install -g npm
- run: npm ci
- run: npm run test:browser -- --browsers ${{ matrix.browser }}
1 change: 1 addition & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
node-version: "18"

# npm@9 may fail with https://github.com/npm/cli/issues/6723
# npm@10 may fail with "GitFetcher requires an Arborist constructor to pack a tarball"
- run: npm install -g npm@8
- run: npm ci
- run: npm run test:fuzz
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files.eol": "\n",
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"instanceof",
Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ Name|Type|Default
extensionCodec | ExtensionCodec | `ExtensionCodec.defaultCodec`
context | user-defined | -
useBigInt64 | boolean | false
rawStrings | boolean | false
maxStrLength | number | `4_294_967_295` (UINT32_MAX)
maxBinLength | number | `4_294_967_295` (UINT32_MAX)
maxArrayLength | number | `4_294_967_295` (UINT32_MAX)
maxMapLength | number | `4_294_967_295` (UINT32_MAX)
maxExtLength | number | `4_294_967_295` (UINT32_MAX)

To skip UTF-8 decoding of strings, `rawStrings` can be set to `true`. In this case, strings are decoded into `Uint8Array`.

You can use `max${Type}Length` to limit the length of each type decoded.

### `decodeMulti(buffer: ArrayLike<number> | BufferSource, options?: DecoderOptions): Generator<unknown, void, unknown>`
Expand Down Expand Up @@ -498,18 +501,19 @@ null, undefined|nil|null (*1)
boolean (true, false)|bool family|boolean (true, false)
number (53-bit int)|int family|number
number (64-bit float)|float family|number
string|str family|string
ArrayBufferView |bin family|Uint8Array (*2)
string|str family|string (*2)
ArrayBufferView |bin family|Uint8Array (*3)
Array|array family|Array
Object|map family|Object (*3)
Date|timestamp ext family|Date (*4)
bigint|N/A|N/A (*5)
Object|map family|Object (*4)
Date|timestamp ext family|Date (*5)
bigint|N/A|N/A (*6)

* *1 Both `null` and `undefined` are mapped to `nil` (`0xC0`) type, and are decoded into `null`
* *2 Any `ArrayBufferView`s including NodeJS's `Buffer` are mapped to `bin` family, and are decoded into `Uint8Array`
* *3 In handling `Object`, it is regarded as `Record<string, unknown>` in terms of TypeScript
* *4 MessagePack timestamps may have nanoseconds, which will lost when it is decoded into JavaScript `Date`. This behavior can be overridden by registering `-1` for the extension codec.
* *5 bigint is not supported in `useBigInt64: false` mode, but you can define an extension codec for it.
* *2 If you'd like to skip UTF-8 decoding of strings, set `rawStrings: true`. In this case, strings are decoded into `Uint8Array`.
* *3 Any `ArrayBufferView`s including NodeJS's `Buffer` are mapped to `bin` family, and are decoded into `Uint8Array`
* *4 In handling `Object`, it is regarded as `Record<string, unknown>` in terms of TypeScript
* *5 MessagePack timestamps may have nanoseconds, which will lost when it is decoded into JavaScript `Date`. This behavior can be overridden by registering `-1` for the extension codec.
* *6 bigint is not supported in `useBigInt64: false` mode, but you can define an extension codec for it.

If you set `useBigInt64: true`, the following mapping is used:

Expand All @@ -519,15 +523,15 @@ null, undefined|nil|null
boolean (true, false)|bool family|boolean (true, false)
**number (32-bit int)**|int family|number
**number (except for the above)**|float family|number
**bigint**|int64 / uint64|bigint (*6)
**bigint**|int64 / uint64|bigint (*7)
string|str family|string
ArrayBufferView |bin family|Uint8Array
Array|array family|Array
Object|map family|Object
Date|timestamp ext family|Date


* *6 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.
* *7 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.

## Prerequisites

Expand Down
122 changes: 122 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import path from "node:path";
import { fileURLToPath } from "node:url";

import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import typescriptEslintEslintPlugin from "@typescript-eslint/eslint-plugin";
import tsdoc from "eslint-plugin-tsdoc";
import tsParser from "@typescript-eslint/parser";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["**/*.js"],
}, ...fixupConfigRules(compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
)), {
plugins: {
"@typescript-eslint": fixupPluginRules(typescriptEslintEslintPlugin),
tsdoc,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: "script",

parserOptions: {
project: "./tsconfig.json",
},
},

settings: {},

rules: {
"no-constant-condition": ["warn", {
checkLoops: false,
}],

"no-useless-escape": "warn",
"no-console": "warn",
"no-var": "warn",
"no-return-await": "warn",
"prefer-const": "warn",
"guard-for-in": "warn",
curly: "warn",
"no-param-reassign": "warn",
"prefer-spread": "warn",
"import/no-unresolved": "off",
"import/no-cycle": "error",
"import/no-default-export": "warn",
"tsdoc/syntax": "warn",
"@typescript-eslint/await-thenable": "warn",

"@typescript-eslint/array-type": ["warn", {
default: "generic",
}],

"@typescript-eslint/naming-convention": ["warn", {
selector: "default",
format: ["camelCase", "UPPER_CASE", "PascalCase"],
leadingUnderscore: "allow",
}, {
selector: "typeLike",
format: ["PascalCase"],
leadingUnderscore: "allow",
}],

"@typescript-eslint/restrict-plus-operands": "warn",
//"@typescript-eslint/no-throw-literal": "warn",
"@typescript-eslint/unbound-method": "warn",
"@typescript-eslint/explicit-module-boundary-types": "warn",
//"@typescript-eslint/no-extra-semi": "warn",
"@typescript-eslint/no-extra-non-null-assertion": "warn",

"@typescript-eslint/no-unused-vars": ["warn", {
argsIgnorePattern: "^_",
}],

"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-call": "warn",

"@typescript-eslint/no-unnecessary-condition": ["warn", {
allowConstantLoopConditions: true,
}],

"@typescript-eslint/no-unnecessary-type-constraint": "warn",
"@typescript-eslint/no-implied-eval": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-invalid-void-type": "warn",
"@typescript-eslint/no-loss-of-precision": "warn",
"@typescript-eslint/no-confusing-void-expression": "warn",
"@typescript-eslint/no-redundant-type-constituents": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-includes": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
"@typescript-eslint/prefer-readonly": "warn",
"@typescript-eslint/prefer-regexp-exec": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-ts-expect-error": "warn",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-ts-comment": "off",
},
}];
Loading

0 comments on commit c7e0d03

Please sign in to comment.