Skip to content

Releases: bare-ts/bare

v0.18.0

26 Oct 22:17
v0.18.0
b14ae4f

Choose a tag to compare

v0.18.0 Pre-release
Pre-release
  • Struct field names can now be in snake_case.

    Previously, only field names in camelCase were allowed in a BARE schema.
    The 14th draft of BARE allows field names in camelCase, snake_case or mixed_Case.
    The --pedantic option ensures that a field name is either in camelCase or snake_case.

    snake_case and mixed_Case are normalized to camelCase for JavaScript and TypeScript generators.

  • Improve the command line help message.

    Hopefully, this will make the provided options more explanatory.
    Also, we improved the documentation about type correspondence between BARE and TypeScript.

v0.16.1

12 Oct 23:55
v0.16.1
e07987d

Choose a tag to compare

v0.16.1 Pre-release
Pre-release
  • Fix CLI argument parsing when using compile command to properly identify schema files

v0.17.0

03 May 16:02
Immutable release. Only release title and notes can be modified.
v0.17.0
ada3a75

Choose a tag to compare

v0.17.0 Pre-release
Pre-release
  • BREAKING CHANGES: require tags in unions and enum to be declared in ascending order.

    This is a requirement introduced by the 12th draft of BARE.

    The following BARE schema is now invalid:

    type Gender enum {
        FEMALE = 1
        FLUID = 2
        MALE = 0
    }
    
  • Support data (binary blobs) as map keys.

    This is a change introduced by the 13th draft of BARE.

    The following BARE schema is now valid:

    type Dict map<data><u32>
    
  • BREAKING CHANGES: require Node.js 20.19.0 or above

    This allows us to use import attributes.
    Their support has been introduced in Node.js 20.10.0.

    Requiring NodeJs 20.19.0 and above ensures that users may require an ESM module.
    This drastically simplifies our package.json's exports conditions,
    and prevent dual-package hazard.
    As a result, we no longer ship a CommonJS version of the package.

  • BREAKING CHANGES: rename generate and checkSemantic into generateJs and check.

    - import { generate, checkSemantic } from "@bare-ts/tools"
    + import { generateJs, check } from "@bare-ts/tools"

v0.16.0

02 Nov 12:37
Immutable release. Only release title and notes can be modified.
v0.16.0
63e47c4

Choose a tag to compare

v0.16.0 Pre-release
Pre-release
  • BREAKING CHANGES: require Node.js 20.0.0 or above

    This allows us to use the built-in Node.js CLI parser and then to remove the Commander.js dependency.
    This reduces the standalone binary size from 77KB to 45KB (42%).

    Additionally, bare compile schema.bare can now be shortened to bare schema.bare.
    compile is optional.

  • Support require(esm) in Node.js v22.10 and above

    This package now has the new exports condition module-sync.
    This allows users of Node.js v22.10 and above to import the ESM version of the package using require.
    This 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 Node.js v20.0.0 or above, we can safely remove main.

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

v0.15.0

19 Oct 10:38
v0.15.0
e53bd48

Choose a tag to compare

v0.15.0 Pre-release
Pre-release
  • BREAKING CHANGES: require node 16.9.0 or above

  • BREAKING CHANGES: promote regular comments to doc-comments

    Previously, bare-ts introduced a special syntax for doc-comments:

    type Gender enum {
        ## Be inclusive :)
        FLUID
        MALE
        ## One is not born, but becomes a woman
        ##                  -- Simone de Beauvoir
        FEMALE
    }
    
    ## A Person with:
    ## - a name
    ## - a gender
    type Person {
        ## person's name
        name: str
        ## person's gender
        gender: optional<Gender>
    }
    

    This syntax is not part of the BARE specification.
    Thus, the syntax is not portable between BARE_ implementations.
    To avoid this issue, bare-ts_ now uses regular comments as doc-comments.
    Every comment that precedes a type definition, an enum value, or a field is a doc-comment.
    The previous schema can now be written as follows:

    type Gender enum {
        # Be inclusive :)
        FLUID
        MALE
        # One is not born, but becomes a woman
        #                  -- Simone de Beauvoir
        FEMALE
    }
    
    # A Person with:
    # - a name
    # - a gender
    type Person {
        # person's name
        name: str
        # person's gender
        gender: optional<Gender>
    }
    
  • BREAKING CHANGES: remove option --import-config

    Instead of importing a custom config, you can now pass the config through any encode function.

    For instance, using the example of the README:

    const payload = encodeContacts(contacts, {
        initialBufferLength: 256 /* bytes */,
        maxBufferLength: 512 /* bytes */,
    })

    A default configuration is applied if no one is passed:

    const payload = encodeContacts(contacts) // use the default config
  • BREAKING CHANGES: replace locations with offsets

    Previously, every node and compiler errors carried a loc or location property.
    A location object contained a filename, line, col, and offset properties.

    The filename property is now contained in the AST root in the property filename.
    loc and location are replaced by offset.

    The line and column numbers must now be computed using the offset.

v0.14.0

19 Jun 15:33
v0.14.0
5e5492b

Choose a tag to compare

v0.14.0 Pre-release
Pre-release
  • BREAKING CHANGES: enum member names in PascalCase instead of CONSTANT_CASE

    In a bare schema, an enum variant must be in CONSTANT_CASE:

    type Status enum {
        OPEN = 0
        CLOSE = 1
    }
    

    Previously, bare-ts preserved the case:

    export enum Status {
        OPEN = "OPEN",
        CLOSE = "CLOSE",
    }

    To follow the TypeScript convention, the case is now in PascalCase.
    Thus, bare-ts generates the following code:

    export enum Status {
        Open = "Open",
        Close = "Close",
    }
  • BREAKING CHANGES: remove option --import-factory

    Previously, bare-ts allowed external factory functions to build struct objects.
    For now, there is no replacement for this feature.

  • BREAKING CHANGES: remove option --use-quoted-property

    Previously, bare-ts allowed emitting JavaScript code with all object properties quoted.
    This feature was under-used and against the JavaScript conventions.

  • Fix name clashes

    Previously, bare-ts did not support the use of aliases like Map or Uint8Array.
    Now, it properly handles these aliases and uses globalThis when necessary.

v0.13.0

20 Feb 21:03
v0.13.0
d900821

Choose a tag to compare

v0.13.0 Pre-release
Pre-release

This release introduces several breaking changes that widely improve the usage of unions and flat unions.
Union tags now use type alias as value.
--use-flat-union is removed in favor of --use-primitive-flat-union and --use-struct-flat-union.
Union flattening now uses a "best-effort approach".

  • BREAKING CHANGES: use strings tags for union of aliases

    bare-ts outputs now string tags for unions of aliases.
    You can obtain the previous behavior with the option --use-int-tag.

    The following schema ...

    type Person struct { name: str }
    type Organization struct { name: str }
    type Contact union { Person | Organization }
    

    ... generates the following types:

    export type Person = { readonly name: string }
    export type Organization = { readonly name: string }
    export type Contact =
        | { tag: "Person"; val: Person }
        | { tag: "Organization"; val: Organization }

    This makes code more readable and allow assigning between compatible unions.

    Using the option --use-int-tag, you obtain the previous output:

    export type Person = { readonly name: string }
    export type Organization = { readonly name: string }
    export type Contact =
        | { tag: 0; val: Person }
        | { tag: 1; val: Organization }
  • BREAKING CHANGES: use type alias as tag's value for flat unions of structs

    bare-ts allows flat unions of aliased structs.
    Previously, it used the type alias in underscore_case as tag's value.
    Now, it uses the type alias in its original case.

    For instance, the following union:

    type BoxedU32 struct { val: u32 }
    type BoxedStr struct { val: str }
    type Boxed union { BoxedU32 | BoxedStr }
    

    can be flatten (under --use-flat-union) to:

    export type BoxedU32 = {
    -   readonly tag: "BOXED_U32", // Previous output
    +   readonly tag: "BoxedU32", // New output
        readonly val: u32,
    }
    
    export type BoxedStr = {
    -   readonly tag: "BOXED_STR", // Previous output
    +   readonly tag: "BoxedStr", // New output
        readonly val: string,
    }
    
    export type Boxed = BoxedU32 | BoxedStr
  • BREAKING CHANGES: split --use-flat-union into --use-primitive-flat-union and --use-struct-flat-union

    Use --use-primitive-flat-union and --use-struct-flat-union instead of --use-flat-union.

  • Flatten unions when possible under --use-primitive-flat-union and --use-struct-flat-union

    bare-ts is able to flatten unions that consist of:

    1. basic types (bool, u8, str, ...) that have distinct typeof values
    2. aliased structs
    3. (anonymous) structs

    Previously, use-flat-union required that all unions be flattened.
    This avoided introducing a "best-effort approach".
    However, this was too restrictive.
    A "best-effort approach" seems acceptable since it is opted in.
    Now, bare-ts attempts to flatten a union and falls back to a tagged union.

    Under --use-struct-flat-union, the following schema...

    type A union { bool | f64 | str }
    type B union { f64 | i32 }
    

    ...compiles to the following types:

    type A = boolean | number | string
    type B = { tag: 0; val: number } | { tag: 1; val: number }

    Note that B is not flatten because f64 and i32 have the same typeof value (number).

    Under --use-struct-flat-union, the following schema...

    type X struct { ... }
    type Y struct { ... }
    type XY union { X | Y }
    type Z Y
    type XZ union { X | Z }
    type Anonymous union { struct { ... } | struct { ... } }
    

    ...compiles to the following types:

    type X = { tag: "X", ... }
    type Y = { tag: "Y", ... }
    type XY = X | Y
    type Z = Y
    type XZ = { tag: "X", val: X } | { tag: "Z", val: "Z" }
    type Anonymous = { tag: 0, ... } | { tag: 1, ... }

    Note that the union XZ is not flatten, because one of the elements is not a struct or an aliased struct.
    Indeed, Z is an aliased alias.

  • Support flat unions of aliased structs and anonymous structs

    Under the option --use-struct-flat-union, the following schema...

    type Person struct { name: str }
    type Entity union {
        | Person
        # Anonymous entity
        | struct { name: str }
    }
    

    ...compiles to the following types

    export type Person = {
        readonly tag: "Person"
        readonly name: string
    }
    export type Entity =
        | Person
        | {
              readonly tag: 1
              readonly name: string
          }

    We introduce this change for consistency purpose.
    You should avoid mixing aliased structs with anonymous structs

v0.12.0

04 Feb 16:28
v0.12.0
616dba2

Choose a tag to compare

v0.12.0 Pre-release
Pre-release
  • Emit ES2020

    bare-ts now publishes ES2020 builds.
    This allows to output smaller builds.
    This should cause no issue since we require a node version ^14.18 or >=16.

  • Allow root types that resolve to void

    Since the 0.9.0 version, root types that resolve to void are forbidden.

    To conform with the bare specification, they are now allowed.
    This makes valid the following schema:

    type Root void
    
  • Add option --lib to prevent decode and encode generation

    A decoder and encoder are generated for every root types that doesn't resolve to void.
    The --lib flag prevents this generation.

    This is particularly useful for libraries that export only readers and writers.

  • BREAKING CHANGES: emit type aliases instead of interfaces

    As a consequence, it is no longer possible to rely
    on interface-merging for augmenting an emitted type.

v0.11.0

06 Jul 15:53
v0.11.0
ca344bc

Choose a tag to compare

v0.11.0 Pre-release
Pre-release
  • Remove option --use-lax-optional

    This avoids to break bijective encoding.

v0.10.0

22 Jun 20:16
v0.10.0
248ea70

Choose a tag to compare

v0.10.0 Pre-release
Pre-release
  • Automatically discriminate aliased structs in flat unions

    @bare-ts is now able to automatically add a discriminator field for
    aliased structs in flat union.

    The name of the discriminator field is tag.
    For now, it is not possible to flatten aliased structs with at least
    one field named tag.

    Thus, under the option --use-flat-union, the following BARE types:

    type X struct { ... }
    type Y struct { ... }
    type XY union { X | Y }
    

    translate to the following TypeScript types:

    export interface X { readonly tag: "X"; ... }
    export interface Y { readonly tag: "Y"; ... }
    export type XY = X | Y
  • Allow flat unions of anonymous structs

    @bare-ts now accepts flat unions of anonymous structs.
    It automatically uses the union tags to discriminate the structs.

    Under the option --use-flat-union, the following BARE types:

    type XY union { struct { ... } | struct { ... } }
    

    translate to the following TypeScript types:

    export type XY = { readonly tag: 0, ... } | { readonly tag: 1, ... }
  • Forbid flat unions of transitively aliased classes

    @bare-ts previously allowed flat unions of transitively aliased classes.
    It now rejects the following schema under the option --use-flat-union:

    type Named struct { name: str }
    type Person Named
    type Message union { Person }
    
  • Require Node 14.18.0 or above

    @bare-ts now requires Node 14.18.0 or above.
    This enables @bare-ts/tools to internally use node: prefixes
    for importing nodes' built-ins.