Releases: bare-ts/bare
v0.16.0
-
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%). -
Support
require(esm)
in Node.js v22.10 and aboveThis 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 usingrequire
.
This avoids the issues of dual-package hazard. -
Remove
package.json
main
andmodule
fieldsThe
main
andmodule
fields supplemented by theexports
fields.
exports
is supported since Node.js v12.7.0
Since we require Node.js v20.0.0 or above, we can safely removemain
.All major bundlers now support
exports
.
Hence, we can also remove themodule
field.
v0.15.0
-
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
orlocation
property.
A location object contained afilename
,line
,col
, andoffset
properties.The
filename
property is now contained in the AST root in the propertyfilename
.
loc
andlocation
are replaced byoffset
.The line and column numbers must now be computed using the offset.
v0.14.0
-
BREAKING CHANGES: enum member names in
PascalCase
instead ofCONSTANT_CASE
In a bare schema, an
enum
variant must be inCONSTANT_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
orUint8Array
.
Now, it properly handles these aliases and usesglobalThis
when necessary.
v0.13.0
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 inunderscore_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:
- basic types (bool, u8, str, ...) that have distinct
typeof
values - aliased structs
- (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 becausef64
andi32
have the sametypeof
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. - basic types (bool, u8, str, ...) that have distinct
-
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
-
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 preventdecode
andencode
generationA 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
-
Remove option
--use-lax-optional
This avoids to break bijective encoding.
v0.10.0
-
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 namedtag
.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 usenode:
prefixes
for importing nodes' built-ins.
v0.9.0
-
Rename
bare-ts
CLI tobare
-
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
-
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, whilePerson
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:
-
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.
-
Implementations that normalize NaNs and consider that NaN
is equal to itselfThis is the implementation chosen by JavaScript
-
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
-
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 }