Releases: bare-ts/bare
v0.18.0
-
Struct field names can now be in
snake_case.Previously, only field names in
camelCasewere allowed in a BARE schema.
The 14th draft of BARE allows field names incamelCase,snake_caseormixed_Case.
The--pedanticoption ensures that a field name is either incamelCaseorsnake_case.snake_caseandmixed_Caseare normalized tocamelCasefor 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
- Fix CLI argument parsing when using
compilecommand to properly identify schema files
v0.17.0
-
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
requirean ESM module.
This drastically simplifies ourpackage.json'sexportsconditions,
and prevent dual-package hazard.
As a result, we no longer ship a CommonJS version of the package. -
BREAKING CHANGES: rename
generateandcheckSemanticintogenerateJsandcheck.- import { generate, checkSemantic } from "@bare-ts/tools" + import { generateJs, check } from "@bare-ts/tools"
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%).Additionally,
bare compile schema.barecan now be shortened tobare schema.bare.
compileis optional. -
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.jsonmainandmodulefieldsThe
mainandmodulefields supplemented by theexportsfields.
exportsis 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 themodulefield.
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-configInstead 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
locorlocationproperty.
A location object contained afilename,line,col, andoffsetproperties.The
filenameproperty is now contained in the AST root in the propertyfilename.
locandlocationare replaced byoffset.The line and column numbers must now be computed using the offset.
v0.14.0
-
BREAKING CHANGES: enum member names in
PascalCaseinstead ofCONSTANT_CASEIn a bare schema, an
enumvariant 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-factoryPreviously, 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-propertyPreviously, 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
MaporUint8Array.
Now, it properly handles these aliases and usesglobalThiswhen 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_caseas 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-unioninto--use-primitive-flat-unionand--use-struct-flat-unionUse
--use-primitive-flat-unionand--use-struct-flat-unioninstead of--use-flat-union. -
Flatten unions when possible under
--use-primitive-flat-unionand--use-struct-flat-unionbare-ts is able to flatten unions that consist of:
- basic types (bool, u8, str, ...) that have distinct
typeofvalues - aliased structs
- (anonymous) structs
Previously,
use-flat-unionrequired 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
Bis not flatten becausef64andi32have the sametypeofvalue (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
XZis not flatten, because one of the elements is not a struct or an aliased struct.
Indeed,Zis 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
voidSince the 0.9.0 version, root types that resolve to
voidare forbidden.To conform with the bare specification, they are now allowed.
This makes valid the following schema:type Root void -
Add option
--libto preventdecodeandencodegenerationA decoder and encoder are generated for every root types that doesn't resolve to
void.
The--libflag 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-optionalThis 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.