Skip to content

Releases: bare-ts/bare

v0.15.0

19 Oct 10:38
v0.15.0
e53bd48
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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.

v0.9.0

12 May 20:36
44f2811
Compare
Choose a tag to compare
v0.9.0 Pre-release
Pre-release
  • Rename bare-ts CLI to bare

  • Forbid use-before-definition

    In the last BARE draft, use-before-definition are disallowed.
    As a consequence, recursive types are also disallowed.

    The following schema is now rejected:

    type Y X
    type X u8
    

    This schema and recursive types are still allowed under the
    option --legacy.

  • Rename --legacy-syntax to --legacy

  • Annotate your schema with doc-comments

    @bare-ts/tool is now able to recognize a doc-comment and to document
    the generated code with them.

    A BARE doc-comment consists in two comment marks ##.
    Doc-comments can only document:

    • type definitions
    • enum values
    • struct fields

    The following schema documents these three kinds of object:

    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>
    }
    

    Note that this syntax is not part of the BARE specification.
    Thus, this is not portable between distinct implementations.

  • Add BARE code generator

    @bare-ts/tools is now able to output BARE schemas.

    This gives a basic way to format a schema.
    Note that comments (except doc comments) are stripped out.

    bare-ts compile schema.bare -o schema.bare
    bare-ts compile schema.bare --generator 'bare'
    
  • Remove options --main and --no-main

    The previous version introduced automatic promotion of root type aliases
    as main type aliases. Root type aliases are type aliases that are not
    referred by a type in the schema. Main type aliases are types used
    to decode and encode messages.

    For the sake of simplicity, main type aliases and root types aliases
    are now identical.

    In the following schema, Post is the only root/main type alias.

    type Person struct { name: str }
    type Post struct { author: Person }
    
  • Forbid root types that resolve to void

    The following schema is now invalid:

    type Root void
    

    This is not part of the BARE specification.

  • Do not emit read/write for types resolving to void

v0.8.0

29 Apr 20:48
9292d80
Compare
Choose a tag to compare
v0.8.0 Pre-release
Pre-release
  • Require @bare-ts/lib v0.3.x

  • Automatically promote root type aliases as main type aliases

    @bare-ts/tool generates encoders and decoders for main type aliases.
    Main type aliases can be selected with the option --main:

    bare-ts compile schema.bare --main Post
    
    # schema.bare
    type Person struct { name: str }
    type Post struct { author: Person }
    

    If the option --main is not set, then @bare-ts/tool promotes now
    root type aliases as main type aliases. Root type aliases are type aliases
    that are not referred by a type in the schema.

    In the previous schema, Post is a root type alias, while Person is not.
    The following command has now the same effect as the previous one:

    bare-ts compile schema.bare
    

    It promotes Post as a main type aliases.

    To avoid the promotion of root types, you must use the option --no-main:

    bare-ts compile schema.bare --no-main
    

    --no-main and --main cannot be both set.

  • BREAKING CHANGES: forbid f32 and f64 as map key type

    According to IEEE-754 2019:
    NaN (Not a Number) is not equal to any value, including itself.

    This inequality leads to different implementations:

    1. Implementations that "follows" the standard

      In this case, an unbounded number of values may be bind to the key NaN
      and cannot be accessed.

      This is the implementation chosen by Golang.

    2. Implementations that normalize NaNs and consider that NaN
      is equal to itself

      This is the implementation chosen by JavaScript

    3. Implementations that rely on the binary comparison of NaNs

    This makes complex the support of f32 and f64 as map key type.

    To avoid this complexity the ongoing BARE draft forbids their usage as
    map key type.

  • Allow leading and trailing pipes in unions

    The following schema is now valid:

    type LeadingPipe union {
        | u8
    }
    
    type TrailingPipe union {
        u8 |
    }
    
  • Do not emit trailing spaces in code generation

v0.7.0

24 Apr 15:26
f239bee
Compare
Choose a tag to compare
v0.7.0 Pre-release
Pre-release
  • BREAKING CHANGES: require node versions that support ESM

    @bare-ts/tools requires now a node versions that support
    ECMAScript Modules.

    Note that, @bare-ts/tools still exports a CommonJS build.

  • Add pure annotation in generated code

    Pure annotations enables to bundler to detect pure function calls.
    @bare-ts/tools adds now these annotations in top-level function calls.

  • Allow circular references where possible

    @bare-ts/tools was previously conservative about circular references.
    It now allows all circular references that can encode at least one
    finite message. The following circular references are now allowed:

    type A list<A>
    type B map<str><B>
    type C list<optional<C>>[2]
    type D list<union { D | str }>[2]
    type E optional<E>
    type F union { F | str }
    

    The following circular references are still rejected:

    type X list<A>[2]
    type Y union { Y }
    type Z struct { field: Z }
    

v0.6.0

31 Mar 18:07
b0befb2
Compare
Choose a tag to compare
v0.6.0 Pre-release
Pre-release
  • Update BARE syntax

    The new syntax for BARE schema is now supported.

    Legacy syntax is now reported as an error.
    To allow legacy syntax use the option --legacy-syntax.