Socket
Socket
Sign inDemoInstall

@deepkit/bson

Package Overview
Dependencies
11
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @deepkit/bson

Deepkit BSON parser


Version published
Weekly downloads
1K
decreased by-3.62%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.0.1-alpha.148 (2024-05-04)

Features

  • type: new TemplateState.touch and isTypeClassOf (cdf3272)
  • type: support lower/mixed case as identifier for enum values (ce0166e)
  • type: support mixed case enum member in union resolver (96dd2d8)

Readme

Source

BSON

@deepkit/bson is a high-performance TS implementation of a parser and serializer for BSON, the MongoDB Binary JSON format. It's the fastest JS BSON parser, even faster than native JSON.parse/stringify.

Deepkit has reimplemented it because it's a high-performance framework and both the official JS (js-bson) and C++ (bson-ext) packages are too slow. How slow? When converting 10k elements in an array, js-bson takes 25ms, bson-ext takes 31ms, whiles JSON.parse takes only 5ms. This makes the official BSON parser 5x slower than native JSON.parse. deepkit/type-bson on the other hand takes only 2ms and is therefore 13x faster.

Benchmark

Parsing BSON buffer that contains an array with 10k objects.

MethodTime (ms)
official native bson-ext31ms
official js-bson25ms
deepkit/bson generic v26ms
deepkit/bson generic v34ms
JSON.parse5ms
deepkit/type JIT2ms

Serializing an array with 10k objects.

MethodTime (ms)
official native bson-ext39ms
official js-bson33ms
JSON.stringify5ms
deepkit/bson JIT2ms

"deepkit/bson JIT" means a parser/serializer based on a schema like so:

import {t} from '@deepkit/type';
import {getBSONDecoder} from '@deepkit/bson';

interface Model {
    username: string;
    tags: string[];
    priority: number;
}

const decoder = getBSONDecoder<Model>();
const bson = new Buffer([]);

const document = decoder(bson);

whereas "deepkit/type generic" means schema-less:

import {parseObject, ParserV2, ParserV3} from '@deepkit/bson';
const bson = new Buffer([]);

const object1 = parseObject(new ParserV2(bson));

const object2 = parseObject(new ParserV3(bson));

Differences

There are a couple of differences to the official serializer.

  • ObjectId is deserialized as string.
  • UUID is deserialized as string.
  • BigInt is supported and serialized as long.
  • Unlimited size BigInt supported (serialised as binary)
  • Long is deserialized as BigInt.

FAQs

Last updated on 04 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc