Skip to content

Releases: bare-ts/lib

v0.7.0

26 Jan 22:29
v0.7.0
4e372d4

Choose a tag to compare

v0.7.0 Pre-release
Pre-release
  • Fix writeUintSafe and writeIntSafe by encoding too large numbers in a canonical way.

    Although the library provides assertions that reject valid inputs, it allows users to disable them.
    Even when assertions are disabled, the library must still provide valid encoded values.
    Previously, writeUintSafe and writeIntSafe might output a non-canonical encoding for numbers that were too large.
    It now robustly handles invalid input numbers that are too large.

  • BREAKING CHANGES: require Node.js 16.9.0 or above.

    This allows us to remove code for BareError#cause which is now natively supported by Error.

v0.6.1

05 Jan 18:08
v0.6.1
5162865

Choose a tag to compare

v0.6.1 Pre-release
Pre-release
  • Fix writeUintSafe32 that wrongly encoded numbers larger than 16383 (2e14 - 1)

    This bug affected the encoding of variable-length arrays with more than 16383 items.

v0.4.1

05 Jan 18:02
v0.4.1
b09f576

Choose a tag to compare

v0.4.1 Pre-release
Pre-release
  • Fix writeUintSafe32 that wrongly encoded numbers larger than 16383 (2e14 - 1)

    This bug affected the encoding of variable-length arrays with more than 16383 items.

v0.6.0

16 Nov 21:38
v0.6.0
7217952

Choose a tag to compare

v0.6.0 Pre-release
Pre-release
  • Support resizable ArrayBuffer and growable SharedArrayBuffer

    ES2024 introduced resizable ArrayBuffer and growable SharedArrayBuffer.
    @bare-ts/lib now handle these new features by resizing and growing in-place the buffer
    when it reserves space for writing.

    Note that the library still respects the maxBufferLength configuration.

    If maxBufferLength is greater than the buffer's maxByteLength, while a new
    buffer is allocated once maxByteLength is exceeded.

    In the following code, the buffer is resized in-place when writeFixedString is called.

    import * as bare from "@bare-ts/lib"
    
    const resizableBuffer = new ArrayBuffer(0, { maxByteLength: 10 })
    
    const config = bare.Config({ initialBufferLength: 0, maxBufferLength: 10 })
    const bc = new bare.ByteCursor(new Uint8Array(resizableBuffer), config)
    
    bare.writeFixedString(bc, "bare")
  • Export assert, DEV and integer validators

    @bare-ts/lib now exports an assert function and integer validators such as isI32.
    We plan to use these functions in a future version of @bare-ts/tools.

    The library also exports a DEV constant that is true if the development condition is passed,
    or if NODE_ENV is set to development under the node condition.
    Use the Node's CLI option --conditions to pass the development condition.

    These functions should only be used for validating arguments of BARE decoders and encoders.

v0.5.0

10 Nov 12:20
v0.5.0
b1574fe

Choose a tag to compare

v0.5.0 Pre-release
Pre-release
  • BREAKING CHANGES: require TypeScript 5.7 or above

    JavaScript has two buffer types: ArrayBuffer and SharedArrayBuffer.
    Before ES2024, TypeScript treated them as a single type.
    ES2024 introduced distinct features for ArrayBuffer and SharedArrayBuffer.
    To take this divergence into account, TypeScript 5.7 added a generic parameter to buffer views.
    By default, it is set to ArrayBufferLike that is a supertype to ArrayBuffer and SharedArrayBuffer.
    This change is backward compatible.

    TypeScript 5.9 went beyond and introduced a breaking change:
    Buffer's views no longer extend ArrayBuffer.
    Moreover, ArrayBufferLike cannot be assigned to ArrayBuffer.

    To accommodate with this change, all BARE read functions now return a view parametrized with ArrayBuffer.
    For example, readU8Array returns Uint8Array<ArrayBuffer>.
    Because we now use parametrized views like Uint8Array<ArrayBuffer>, you have to use TypeScript 5.7 or above.

    BARE write functions still accept view with any buffer types.

  • Export the default bare configuration

    import * as bare from "@bare-ts/lib"
    
    const config: bare.Config = bare.DEFAULT_CONFIG
  • Support require(esm) in Node.js v22.10 and above

    This package now has the new exports condition module-sync.
    It allows users of Node.js v22.10 and above to import the ESM version of the package using require.
    It avoids the issues of dual-package hazard.

  • Remove package.json main and module fields

    The main and module fields supplemented by the exports fields.
    exports is supported since Node.js v12.7.0
    Since we require a version above, we can safely remove main.

    All major bundlers now support exports.
    Hence, we can also remove the module field.

v0.4.0

19 Jun 15:15
v0.4.0
460afef

Choose a tag to compare

v0.4.0 Pre-release
Pre-release
  • BREAKING CHANGES: remove ByteCursor methods

    To make bare-ts/lib API uniform, methods of ByteCursor are replaced by regular functions.

      import * as bare from "@bare-ts/lib"
    
      const bc = new bare.ByteCursor(new Uint8Array(5), bare.Config({}))
    - bc.check(5)
    - bc.reserve(5)
    - bc.read(5)
    + bare.check(bc, 5)
    + bare.reserve(bc, 5)
    + bare.readUnsafeU8FixedArray(bc, 5)
  • BREAKING CHANGES: remove textDecoderThreshold and textEncoderThreshold configuration

    Calls to native TextDecoder.decode and TextEncoder.encode have a fixed cost.
    This cost outperforms the native performance to decode and encode small strings.

    bare-ts uses a custom implementation to decode and encode small strings.
    The choice between the custom and the native codecs is based on thresholds.
    These threshold were configurable via textDecoderThreshold and textEncoderThreshold config properties.

    This is not clear whether this configuration is worth to expose.
    Most of decoded and encoded strings are small.
    Fixed thresholds seem fair enough.

  • Assertions and development mode

    Previously, bare-ts enabled a few assertions to check some function arguments.
    For instance, the following code could trigger an AssertionError:

    import * as bare from "@bare-ts/lib"
    
    const bc = new bare.ByteCursor(new Uint8Array(5), bare.Config({}))
    bare.writeU8(bc, 2**10) // AssertionError: too large number

    Assertions are now disabled by default.
    They are enabled under the following condition:

    • The code is executed under node with NODE_ENV=development

    • The code is executed or bundled under development condition.

    New assertions were added to improve error reporting on development.
    More assertions could be added in the future.

    Because assertions can be disabled, we improved the code robustness:
    All uint/int writters truncate their input to ensure that the number of written bytes is bounded.

v0.3.0

25 Apr 20:59
1e25363

Choose a tag to compare

v0.3.0 Pre-release
Pre-release
  • Full compliance to IEEE-754 (floating point numbers)

    NaN is now a valid value for f32 and f64.

  • Remove {read,write}Void

  • Make @bare-ts/lib platform-agnostic

    Use your favorite ESM-ready CDN and simply import @bare-ts/lib.
    This was made possible by removing the dependency over node:assert.

v0.2.0

16 Jan 17:47
39c8a3b

Choose a tag to compare

v0.2.0 Pre-release
Pre-release
  • Improve performance for reading and writing strings

  • Improve performance for reading variable integers encoded on a single byte

  • Add a reader and a writer for fixed-strings

    Users have now access to two new functions that enable to read and
    write fixed-length strings.

    bare.readFixedString(bc, /* string's length in bytes */ 4)
    bare.writeFixedString(bc, "bare")
  • Simplification of ByteCursor

  • BREAKING CHANGE: rename all decode/encode into read/write

    read/write feel more low-level than decode/encode.
    read/write are also more used among BARE implementations than decode/encode.
    Moreover, in JS, decode and encode are used for high-level API such as
    TextDEcoder and TextEncoder.

    bare.decodeU8(bc) // Previously
    bare.readU8(bc) // Now
    
    bare.encodeU8(bc, 42) // Previously
    bare.writeU8(bc, 42) // Now
  • BREAKING CHANGE: length can no longer be specified for fixed-array writers

    Previously, you had to specify the length of the fixed-array to encode.
    If the given length was different of the actual array's length,
    then an assertion was thrown ("unmatched length").

    It is no longer possible to specify the length.
    As a consequence, the fixed-array writers can no longer assert the length.

    Fixed-array writers now have the same signature as other writers.

    bare.readerU8FixedArray(bc, Uint8Array.of(42, 24), 2) // Previously
    bare.writeU8FixedArray(bc, Uint8Array.of(42, 24)) // Now

    Note that fixed-array readers still require the specification of the
    length:

    bare.decodeU8FixedArray(bc, 2)
  • BREAKING CHANGE: ByteCursor no longer accept ArrayBuffer

    new ByteCursor(new ArrayBuffer(5), config) // Now fails
    new ByteCursor(new Uint8Array(5), config) // Update to this
  • BREAKING CHANGE: remove ByteCursor#write

    Use writeU8FixedArray instead:

    const bc = new ByteCursor(buffer, config)
    
    bc.write(buffer) // Previously
    bare.writeU8FixedArray(bc, buffer) // Now

v0.1.1

09 Jan 16:44
58ddacd

Choose a tag to compare

v0.1.1 Pre-release
Pre-release
  • Fix write offset when byteOffset > 0

    A ByteCursor may be instantiated with an array of bytes such that
    the array's byteOffset is greater than 0.
    The previous ByteCursor.write implementation did not take care of adding this byteOffset to the ByteCursor's offset.

    The following code no longer fail:

    const bytes = Uint8Array.of(42, 24).subarray(1)
    assert(bytes.byteOffset === 1)
    
    const bc = ByteCursor(bytes, ...)
    bc.write(Uint8Array.of(24))
    assert.deepEqual(Array.from(bytes), [42, 24]) // Previously failed
  • Smaller CommonJS bundle

  • Improve byte-length computation of small string

v0.1.0

02 Jan 19:06
ae90dcb

Choose a tag to compare

v0.1.0 Pre-release
Pre-release
  • ByteCursor abstraction to read and write safely a buffer of bytes

  • Enable to configure at runtime:

    • initial buffer length
    • maximum buffer length
    • thresholds (string length) for switching from custom to native UTF-8 decoders/encoders
  • Decoders and encoders for basic types (bool, opaque data, floats, integers, typed arrays, UTF-8 string)