├── .editorconfig ├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .prettierrc.toml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── VERSION.json ├── biome.json ├── docs └── types.md ├── logo.svg ├── package-lock.json ├── package.json ├── scripts ├── generate-tests-corpus.ts ├── print-changelog.sh └── version.sh ├── src ├── ast.ts ├── bin │ └── bare.ts ├── checker.ts ├── configurer.ts ├── core.ts ├── gen-bare.ts ├── gen-js.ts ├── index.ts ├── lexer.test.ts ├── lexer.ts ├── normalizer.ts ├── parser.ts ├── tsconfig.json └── utils │ ├── ast-unrecursive.ts │ └── formatting.ts └── tests-corpus ├── index.test.ts ├── invalid-bare-schema ├── alias-anonymous-struct-legacy │ ├── error.gen.json │ └── schema.bare ├── alias-circular │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── alias-figure │ ├── ast.gen.json │ ├── error.gen.json │ └── schema.bare ├── alias-itself │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── alias-lowercase │ ├── ast.gen.json │ ├── error.gen.json │ └── schema.bare ├── alias-missing-type │ ├── error.gen.json │ └── schema.bare ├── alias-undef │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── alias-wrong-keyword │ ├── error.gen.json │ └── schema.bare ├── alias-wrong-sep-coma │ ├── error.gen.json │ └── schema.bare ├── alias-wrong-sep-equal │ ├── error.gen.json │ └── schema.bare ├── alias-wrong-sep-semicolon │ ├── error.gen.json │ └── schema.bare ├── data-fixed-empty │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── data-fixed-hex │ ├── error.gen.json │ └── schema.bare ├── data-fixed-legacy │ ├── error.gen.json │ └── schema.bare ├── data-fixed-no-end-delim │ ├── error.gen.json │ └── schema.bare ├── data-fixed-too-large │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── duplicated-alias │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── empty-schema │ ├── ast.gen.json │ ├── error.gen.json │ └── schema.bare ├── enum-empty │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── enum-legacy │ ├── error.gen.json │ └── schema.bare ├── enum-no-end-delim │ ├── error.gen.json │ └── schema.bare ├── enum-no-start-delim │ ├── error.gen.json │ └── schema.bare ├── enum-pedantic-partial-val │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── enum-repeated-val │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── enum-too-big-val │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── enum-unsorted │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── enum-val-lowercase │ ├── error.gen.json │ └── schema.bare ├── enum-val-non-int │ ├── error.gen.json │ └── schema.bare ├── enum-val-wrong-sep-coma │ ├── error.gen.json │ └── schema.bare ├── enum-val-wrong-sep-semicolon │ ├── error.gen.json │ └── schema.bare ├── flat-union-undef-alias │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ ├── out.gen.bare │ └── schema.bare ├── list-fixed-circular │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── list-fixed-empty │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── list-fixed-hex │ ├── error.gen.json │ └── schema.bare ├── list-fixed-legacy │ ├── error.gen.json │ └── schema.bare ├── list-fixed-too-large │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── list-legacy │ ├── error.gen.json │ └── schema.bare ├── map-invalid-key-alias │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ ├── out.gen.bare │ └── schema.bare ├── map-invalid-key-float │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── map-legacy │ ├── error.gen.json │ └── schema.bare ├── map-no-start-key-delim │ ├── error.gen.json │ └── schema.bare ├── map-wrong-type-sep │ ├── error.gen.json │ └── schema.bare ├── optional-no-end-delim │ ├── error.gen.json │ └── schema.bare ├── optional-no-start-delim │ ├── error.gen.json │ └── schema.bare ├── string-legacy │ ├── error.gen.json │ └── schema.bare ├── struct-circular-ref │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── struct-empty │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── struct-field-uppercase │ ├── ast.gen.json │ ├── error.gen.json │ └── schema.bare ├── struct-field-wrong-sep-coma │ ├── error.gen.json │ └── schema.bare ├── struct-field-wrong-sep-semicolon │ ├── error.gen.json │ └── schema.bare ├── struct-legacy │ ├── error.gen.json │ └── schema.bare ├── struct-no-end-delim │ ├── error.gen.json │ └── schema.bare ├── struct-no-prop-type-sep │ ├── error.gen.json │ └── schema.bare ├── struct-no-start-delim │ ├── error.gen.json │ └── schema.bare ├── struct-repeated-field │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-empty │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-legacy │ ├── error.gen.json │ └── schema.bare ├── union-missing-type-delim │ ├── error.gen.json │ └── schema.bare ├── union-no-end-delim │ ├── error.gen.json │ └── schema.bare ├── union-non-terminable-circular │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-not-enclosed │ ├── error.gen.json │ └── schema.bare ├── union-pedantic-partial-tag │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-repeated-tag │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ ├── out.gen.bare │ └── schema.bare ├── union-repeated-type │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-tag-hex │ ├── error.gen.json │ └── schema.bare ├── union-tag-unsorted │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ ├── out.gen.bare │ └── schema.bare ├── union-too-big-tag │ ├── ast.gen.json │ ├── config.json │ ├── error.gen.json │ └── schema.bare ├── union-wrong-type-delim │ ├── error.gen.json │ └── schema.bare └── use-before-defined │ ├── ast.gen.json │ ├── error.gen.json │ └── schema.bare ├── tsconfig.json └── valid-bare-schema ├── alias-anonymous-struct-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── alias-doccomment ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── alias-lib ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── alias ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── bigint ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── data-fixed-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── data-fixed ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── data ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-anonymous ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-big-val ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-doccomment ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-int-anonymous ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-int ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-partial-val ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum-val-pedantic ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── enum ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── imported-config ├── ast.gen.json ├── config.json ├── ext.d.ts ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-circular-ref ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-fixed-leading-0 ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-fixed-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-fixed ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list-union-circular-ref ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── list ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map-circular-ref ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map-key-alias ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map-key-data ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map-key-enum ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── map ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── multi-list-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── mutable-map ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── name-clash-mutable ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── name-clash ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── optional-circular ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── optional-undefined ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── optional-union-circular ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── optional ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── root-resolved-void ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── root-void ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── safe-int-list ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── safe-int ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── string-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-anonymous ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-circular-ref-allowed ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-class ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-doccomment ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-keyword-names ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-mutable ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-recursive ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct-reserved-js-names ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── struct ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── typed-array-fixed ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── typed-array ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-big-tag ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-circular ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-composite-type ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-doccomment ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-anonymous-aliased-structs ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-class ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-same-typeof ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-struct-anonymous ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-struct-tag-property ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-struct ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-transitive-alias ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-flat-typeof ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-leading-trailing-pipes ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-legacy ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-optional-circular ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-partial-tag ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-repeated-aliased-type ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-singleton ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-struct-int-tag ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-tag-pedantic ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union-void ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── union ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts └── schema.bare ├── x-bareorg-example ├── ast.gen.json ├── config.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts ├── schema.bare └── user.test.js └── x-readme-example ├── ast.gen.json ├── out.gen.bare ├── out.gen.d.ts ├── out.gen.js ├── out.gen.ts ├── schema.bare └── user.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.json] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_call: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | jobs: 11 | test: 12 | permissions: 13 | contents: read 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4.2.2 17 | - uses: actions/setup-node@v4.2.0 18 | with: 19 | node-version: "22.14.0" 20 | cache: npm 21 | - name: Build and test coverage 22 | run: | 23 | npm ci 24 | npm install c8 25 | npm run coverage 26 | - name: Coveralls 27 | uses: coverallsapp/github-action@master 28 | with: 29 | github-token: ${{ secrets.GITHUB_TOKEN }} 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | coverage 3 | dist 4 | node_modules 5 | *.tsbuildinfo 6 | -------------------------------------------------------------------------------- /.prettierrc.toml: -------------------------------------------------------------------------------- 1 | semi = false -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Victorien Elvinger 2 | Licensed under the MIT License (https://mit-license.org/) -------------------------------------------------------------------------------- /VERSION.json: -------------------------------------------------------------------------------- 1 | "0.17.0" 2 | -------------------------------------------------------------------------------- /scripts/print-changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | # Print a changelog section (default: first section). 5 | 6 | VERSION='' 7 | if test -n "${1:-}" && grep -Eq "^## $1($| )" CHANGELOG.md; then 8 | # The specified version has a dedicated section in the changelog 9 | VERSION="$1" 10 | fi 11 | 12 | # print Changelog of $VERSION 13 | awk -v version="$VERSION" '/^## / { if (p) { exit }; if (version == "" || $2 == version) { p=1; next} } p' CHANGELOG.md 14 | -------------------------------------------------------------------------------- /scripts/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | # check presence of 'Unreleased' string 5 | grep --quiet '^## Unreleased$' CHANGELOG.md 6 | 7 | DATE="$(date -u +%Y-%m-%d)" 8 | 9 | # set version and current date 10 | sed -i "s/^## Unreleased$/## $npm_package_version ($DATE)/" CHANGELOG.md 11 | 12 | echo "\"$npm_package_version\"" > VERSION.json 13 | 14 | git add CHANGELOG.md VERSION.json 15 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tests-corpus/tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "exactOptionalPropertyTypes": false, 6 | "erasableSyntaxOnly": true, 7 | "isolatedDeclarations": true, 8 | "noEmit": false, 9 | "rootDir": ".", 10 | "outDir": "../dist" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-anonymous-struct-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 12, 4 | "message": "use 'struct { ... } or allow '{ ... }' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-anonymous-struct-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Person { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-circular/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 69, 4 | "message": "non-terminable circular references are not allowed." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias0 Alias1 2 | type Alias1 Alias2 3 | type Alias2 Alias3 4 | type Alias3 Alias0 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-figure/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "8u", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 8 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "alias-figure/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-figure/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 0, 4 | "message": "the type name '8u' must not start with a figure or must be internal." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-figure/schema.bare: -------------------------------------------------------------------------------- 1 | type 8u u8 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-itself/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "alias", 9 | "data": "Alias", 10 | "types": null, 11 | "extra": null, 12 | "offset": 11 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "alias-itself/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-itself/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-itself/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 11, 4 | "message": "non-terminable circular references are not allowed." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-itself/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias Alias -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-lowercase/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "lowerCase", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 15 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "alias-lowercase/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-lowercase/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 0, 4 | "message": "the type name 'lowerCase' must be in PascalCase." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-lowercase/schema.bare: -------------------------------------------------------------------------------- 1 | type lowerCase u8 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-missing-type/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 10, 4 | "message": "a type is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-missing-type/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-undef/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-undef/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 48, 4 | "message": "alias 'UndefinedAlias' is not defined." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-undef/schema.bare: -------------------------------------------------------------------------------- 1 | type A struct { 2 | field0: u8 3 | field1: list 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-keyword/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 0, 4 | "message": "'type' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-keyword/schema.bare: -------------------------------------------------------------------------------- 1 | typealias Alias u8 2 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-coma/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 10, 4 | "message": "members cannot be separated by ','." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-coma/schema.bare: -------------------------------------------------------------------------------- 1 | type U8 u8, -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-equal/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 11, 4 | "message": "a type definition and its body cannot be separated by '='." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-equal/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias = u8 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-semicolon/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 10, 4 | "message": "members cannot be separated by ','." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/alias-wrong-sep-semicolon/schema.bare: -------------------------------------------------------------------------------- 1 | type U8 u8, -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-empty/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "EmptyData", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "data", 9 | "data": { 10 | "name": null, 11 | "val": 0, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 20 15 | }, 16 | "types": null, 17 | "extra": null, 18 | "offset": 15 19 | }, 20 | "offset": 0 21 | } 22 | ], 23 | "filename": "data-fixed-empty/schema.bare", 24 | "offset": 0 25 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-empty/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-empty/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 20, 4 | "message": "a fixed list or data must have a length strictly greater than 0." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-empty/schema.bare: -------------------------------------------------------------------------------- 1 | type EmptyData data[0] -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-hex/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 18, 4 | "message": "an unsigned integer is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-hex/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Alias data[0x4] -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 14, 4 | "message": "use 'data[n]' or allow 'data' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Data data<16> -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-no-end-delim/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 20, 4 | "message": "']' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-no-end-delim/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Alias data[4 2 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-too-large/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "EmptyData", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "data", 9 | "data": { 10 | "name": null, 11 | "val": 4294967296, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 20 15 | }, 16 | "types": null, 17 | "extra": null, 18 | "offset": 15 19 | }, 20 | "offset": 0 21 | } 22 | ], 23 | "filename": "data-fixed-too-large/schema.bare", 24 | "offset": 0 25 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-too-large/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-too-large/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 20, 4 | "message": "only length encoded as a u32 are supported." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/data-fixed-too-large/schema.bare: -------------------------------------------------------------------------------- 1 | type EmptyData data[4294967296] # 2**32 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/duplicated-alias/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Duplicated", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 16 13 | }, 14 | "offset": 0 15 | }, 16 | { 17 | "alias": "Duplicated", 18 | "internal": false, 19 | "comment": "", 20 | "type": { 21 | "tag": "u8", 22 | "data": null, 23 | "types": null, 24 | "extra": null, 25 | "offset": 35 26 | }, 27 | "offset": 19 28 | } 29 | ], 30 | "filename": "duplicated-alias/schema.bare", 31 | "offset": 0 32 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/duplicated-alias/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/duplicated-alias/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 19, 4 | "message": "alias 'Duplicated' is already defined." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/duplicated-alias/schema.bare: -------------------------------------------------------------------------------- 1 | type Duplicated u8 2 | type Duplicated u8 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/empty-schema/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [], 3 | "filename": "empty-schema/schema.bare", 4 | "offset": 0 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/empty-schema/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 0, 4 | "message": "a schema cannot be empty." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/empty-schema/schema.bare: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bare-ts/bare/8c0705386f9ae7eef0a2fb113d0e3d8dd40b5208/tests-corpus/invalid-bare-schema/empty-schema/schema.bare -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-empty/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [], 10 | "types": null, 11 | "extra": null, 12 | "offset": 13 13 | }, 14 | "offset": 1 15 | } 16 | ], 17 | "filename": "enum-empty/schema.bare", 18 | "offset": 1 19 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-empty/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-empty/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 13, 4 | "message": "a enum must include at least one member." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-empty/schema.bare: -------------------------------------------------------------------------------- 1 | 2 | type Gender enum {} 3 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 13, 4 | "message": "use 'type Gender enum { ... }' or allow 'enum Gender { ... }' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | 2 | enum Gender { 3 | FLUID 4 | MALE 5 | FEMALE 6 | } 7 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-no-end-delim/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 49, 4 | "message": "'}' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-no-end-delim/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE 4 | FEMALE 5 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-no-start-delim/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 21, 4 | "message": "'{' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-no-start-delim/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum 2 | FLUID 3 | MALE 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-pedantic-partial-val/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pedantic": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-pedantic-partial-val/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 46, 4 | "message": "in pedantic mode, all enum tags must be set. '=' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-pedantic-partial-val/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-repeated-val/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-repeated-val/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 53, 4 | "message": "name of a enum member must be unique." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-repeated-val/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE 4 | FEMALE 5 | FLUID 6 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-too-big-val/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Male", 12 | "val": 1, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Female", 19 | "val": 2, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 36 23 | }, 24 | { 25 | "name": "Fluid", 26 | "val": 9007199254740992, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 51 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-too-big-val/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-too-big-val/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-too-big-val/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 51, 4 | "message": "only safe integers are supported." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-too-big-val/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | MALE = 1 3 | FEMALE = 2 4 | FLUID = 9007199254740992 # this is Number.MAX_SAFE_INTEGER + 1 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-unsorted/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Fluid", 12 | "val": 1, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Male", 19 | "val": 0, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 37 23 | }, 24 | { 25 | "name": "Female", 26 | "val": 2, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 50 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-unsorted/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-unsorted/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pedantic": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-unsorted/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 37, 4 | "message": "All enum tags must be in ascending order." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-unsorted/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 1 3 | MALE = 0 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-lowercase/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 23, 4 | "message": "the name of an enum member must be in CONSTANT_CASE." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-lowercase/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | fluid 3 | male 4 | female 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-non-int/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 31, 4 | "message": "an unsigned integer is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-non-int/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = F 3 | MALE = M 4 | FEMALE = F 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-wrong-sep-coma/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 28, 4 | "message": "members cannot be separated by ','." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-wrong-sep-coma/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID, 3 | MALE, 4 | FEMALE, 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-wrong-sep-semicolon/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 28, 4 | "message": "members cannot be separated by ';'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/enum-val-wrong-sep-semicolon/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID; 3 | MALE; 4 | FEMALE; 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/flat-union-undef-alias/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/flat-union-undef-alias/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 69, 4 | "message": "alias 'BoxedStr' is not defined." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/flat-union-undef-alias/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { 10 | | BoxedU32 = 0 11 | | BoxedStr = 1 12 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/flat-union-undef-alias/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type Boxed union { BoxedU32 | BoxedStr } 6 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-circular/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 43, 4 | "message": "non-terminable circular references are not allowed." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | bestFriends: list[2] 3 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-empty/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "EmptyArray", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": { 10 | "name": null, 11 | "val": 0, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 27 15 | }, 16 | "types": [ 17 | { 18 | "tag": "bool", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 21 23 | } 24 | ], 25 | "extra": null, 26 | "offset": 16 27 | }, 28 | "offset": 0 29 | } 30 | ], 31 | "filename": "list-fixed-empty/schema.bare", 32 | "offset": 0 33 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-empty/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-empty/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 27, 4 | "message": "a fixed list or data must have a length strictly greater than 0." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-empty/schema.bare: -------------------------------------------------------------------------------- 1 | type EmptyArray list[0] -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-hex/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 22, 4 | "message": "an unsigned integer is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-hex/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[0x4] -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 13, 4 | "message": "use 'list[n]' or allow '[n]A' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array [4]str -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-too-large/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "EmptyData", 5 | "internal": false, 6 | "type": { 7 | "tag": "list", 8 | "data": { 9 | "name": null, 10 | "val": 4294967296, 11 | "comment": null, 12 | "extra": null, 13 | "offset": 24 14 | }, 15 | "types": [ 16 | { 17 | "tag": "u8", 18 | "data": null, 19 | "types": null, 20 | "extra": null, 21 | "offset": 20 22 | } 23 | ], 24 | "extra": { 25 | "mut": false, 26 | "typedArray": true, 27 | "unique": false 28 | }, 29 | "offset": 15 30 | }, 31 | "comment": "", 32 | "offset": 0 33 | } 34 | ], 35 | "filename": "list-fixed-too-large/schema.bare", 36 | "offset": 0 37 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-too-large/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-too-large/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 24, 4 | "message": "only length encoded as a u32 are supported." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-fixed-too-large/schema.bare: -------------------------------------------------------------------------------- 1 | type EmptyData list[4294967296] # 2**32 -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 12, 4 | "message": "use 'list[n]' or allow '[n]A' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/list-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type U8List []str -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-alias/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-alias/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 32, 4 | "message": "the key type must be a base type (except f32, f64) or an enum type." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-alias/out.gen.bare: -------------------------------------------------------------------------------- 1 | type KeyType data 2 | 3 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-alias/schema.bare: -------------------------------------------------------------------------------- 1 | type KeyType f64 2 | 3 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-float/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Dict", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "map", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "f64", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 14 17 | }, 18 | { 19 | "tag": "str", 20 | "data": null, 21 | "types": null, 22 | "extra": null, 23 | "offset": 19 24 | } 25 | ], 26 | "extra": null, 27 | "offset": 10 28 | }, 29 | "offset": 0 30 | } 31 | ], 32 | "filename": "map-invalid-key-float/schema.bare", 33 | "offset": 0 34 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-float/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-float/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 14, 4 | "message": "the key type must be a base type (except f32, f64) or an enum type." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-invalid-key-float/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-legacy/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 13, 4 | "message": "use 'map' or allow 'map[A]B' with option '--legacy'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map[str] str -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-no-start-key-delim/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 14, 4 | "message": "'<' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-no-start-key-delim/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map str str -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-wrong-type-sep/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 17, 4 | "message": "every type must be enclosed with '<>'. e.g. 'map'." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/map-wrong-type-sep/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/optional-no-end-delim/error.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CompilerError", 3 | "offset": 28, 4 | "message": "'>' is expected." 5 | } -------------------------------------------------------------------------------- /tests-corpus/invalid-bare-schema/optional-no-end-delim/schema.bare: -------------------------------------------------------------------------------- 1 | type MaybeBool optional 5 | } 6 | 7 | type Gender enum { 8 | FEMALE 9 | FLUID 10 | MALE 11 | } -------------------------------------------------------------------------------- /tests-corpus/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "compilerOptions": { 4 | "lib": [ 5 | "ES2023" 6 | ], 7 | "module": "NodeNext", 8 | "target": "ES2022", 9 | "types": [ 10 | "node" 11 | ], 12 | 13 | "noEmit": true, 14 | 15 | "libReplacement": false, 16 | "resolveJsonModule": true, 17 | "rewriteRelativeImportExtensions": true, 18 | "skipLibCheck": true, 19 | "verbatimModuleSyntax": true, 20 | 21 | "allowUnreachableCode": false, 22 | "exactOptionalPropertyTypes": true, 23 | "noFallthroughCasesInSwitch": true, 24 | "noImplicitOverride": true, 25 | "noImplicitReturns": true, 26 | "strict": true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-anonymous-struct-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-anonymous-struct-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-anonymous-struct-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Person = { 6 | readonly name: string 7 | readonly age: u8 8 | } 9 | 10 | export function readPerson(bc: bare.ByteCursor): Person 11 | 12 | export function writePerson(bc: bare.ByteCursor, x: Person): void 13 | 14 | export function encodePerson(x: Person, config?: Partial): Uint8Array 15 | 16 | export function decodePerson(bytes: Uint8Array): Person 17 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-anonymous-struct-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Person { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-doccomment/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Alias", 5 | "internal": false, 6 | "comment": " First doctring\n", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 30 13 | }, 14 | "offset": 17 15 | }, 16 | { 17 | "alias": "U8Alias2", 18 | "internal": false, 19 | "comment": " multiline\n doctring\n", 20 | "type": { 21 | "tag": "u8", 22 | "data": null, 23 | "types": null, 24 | "extra": null, 25 | "offset": 82 26 | }, 27 | "offset": 68 28 | } 29 | ], 30 | "filename": "alias-doccomment/schema.bare", 31 | "offset": 17 32 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-doccomment/out.gen.bare: -------------------------------------------------------------------------------- 1 | # First doctring 2 | type U8Alias u8 3 | 4 | # multiline 5 | # doctring 6 | type U8Alias2 u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-doccomment/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | /** 6 | * First doctring 7 | */ 8 | export type U8Alias = u8 9 | 10 | export function readU8Alias(bc: bare.ByteCursor): U8Alias 11 | 12 | export function writeU8Alias(bc: bare.ByteCursor, x: U8Alias): void 13 | 14 | export function encodeU8Alias(x: U8Alias, config?: Partial): Uint8Array 15 | 16 | export function decodeU8Alias(bytes: Uint8Array): U8Alias 17 | 18 | /** 19 | * multiline 20 | * doctring 21 | */ 22 | export type U8Alias2 = u8 23 | 24 | export function readU8Alias2(bc: bare.ByteCursor): U8Alias2 25 | 26 | export function writeU8Alias2(bc: bare.ByteCursor, x: U8Alias2): void 27 | 28 | export function encodeU8Alias2(x: U8Alias2, config?: Partial): Uint8Array 29 | 30 | export function decodeU8Alias2(bytes: Uint8Array): U8Alias2 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-doccomment/schema.bare: -------------------------------------------------------------------------------- 1 | # First doctring 2 | type U8Alias u8 3 | 4 | # Second 5 | # 6 | # multiline 7 | # doctring 8 | type U8Alias2 u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 13 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "alias-lib/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "lib": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Alias u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Alias = u8 6 | 7 | export function readU8Alias(bc: bare.ByteCursor): U8Alias 8 | 9 | export function writeU8Alias(bc: bare.ByteCursor, x: U8Alias): void 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export function readU8Alias(bc) { 4 | return bare.readU8(bc) 5 | } 6 | 7 | export function writeU8Alias(bc, x) { 8 | bare.writeU8(bc, x) 9 | } 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/out.gen.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Alias = u8 6 | 7 | export function readU8Alias(bc: bare.ByteCursor): U8Alias { 8 | return bare.readU8(bc) 9 | } 10 | 11 | export function writeU8Alias(bc: bare.ByteCursor, x: U8Alias): void { 12 | bare.writeU8(bc, x) 13 | } 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias-lib/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Alias u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 13 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "alias/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Alias u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Alias = u8 6 | 7 | export function readU8Alias(bc: bare.ByteCursor): U8Alias 8 | 9 | export function writeU8Alias(bc: bare.ByteCursor, x: U8Alias): void 10 | 11 | export function encodeU8Alias(x: U8Alias, config?: Partial): Uint8Array 12 | 13 | export function decodeU8Alias(bytes: Uint8Array): U8Alias 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readU8Alias(bc) { 6 | return bare.readU8(bc) 7 | } 8 | 9 | export function writeU8Alias(bc, x) { 10 | bare.writeU8(bc, x) 11 | } 12 | 13 | export function encodeU8Alias(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeU8Alias(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeU8Alias(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readU8Alias(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/alias/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Alias u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/bigint/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "I64", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "i64", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 9 13 | }, 14 | "offset": 0 15 | }, 16 | { 17 | "alias": "U64", 18 | "internal": false, 19 | "comment": "", 20 | "type": { 21 | "tag": "u64", 22 | "data": null, 23 | "types": null, 24 | "extra": null, 25 | "offset": 22 26 | }, 27 | "offset": 13 28 | } 29 | ], 30 | "filename": "bigint/schema.bare", 31 | "offset": 0 32 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/bigint/out.gen.bare: -------------------------------------------------------------------------------- 1 | type I64 i64 2 | 3 | type U64 u64 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/bigint/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type i64 = bigint 4 | export type u64 = bigint 5 | 6 | export type I64 = i64 7 | 8 | export function readI64(bc: bare.ByteCursor): I64 9 | 10 | export function writeI64(bc: bare.ByteCursor, x: I64): void 11 | 12 | export function encodeI64(x: I64, config?: Partial): Uint8Array 13 | 14 | export function decodeI64(bytes: Uint8Array): I64 15 | 16 | export type U64 = u64 17 | 18 | export function readU64(bc: bare.ByteCursor): U64 19 | 20 | export function writeU64(bc: bare.ByteCursor, x: U64): void 21 | 22 | export function encodeU64(x: U64, config?: Partial): Uint8Array 23 | 24 | export function decodeU64(bytes: Uint8Array): U64 25 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/bigint/schema.bare: -------------------------------------------------------------------------------- 1 | type I64 i64 2 | type U64 u64 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Data", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "data", 9 | "data": { 10 | "name": null, 11 | "val": 16, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 15 15 | }, 16 | "types": null, 17 | "extra": null, 18 | "offset": 10 19 | }, 20 | "offset": 0 21 | } 22 | ], 23 | "filename": "data-fixed-legacy/schema.bare", 24 | "offset": 0 25 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Data data[16] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Data = ArrayBuffer 4 | 5 | export function readData(bc: bare.ByteCursor): Data 6 | 7 | export function writeData(bc: bare.ByteCursor, x: Data): void 8 | 9 | export function encodeData(x: Data, config?: Partial): Uint8Array 10 | 11 | export function decodeData(bytes: Uint8Array): Data 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Data data<16> -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Data", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "data", 9 | "data": { 10 | "name": null, 11 | "val": 16, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 15 15 | }, 16 | "types": null, 17 | "extra": null, 18 | "offset": 10 19 | }, 20 | "offset": 0 21 | } 22 | ], 23 | "filename": "data-fixed/schema.bare", 24 | "offset": 0 25 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Data data[16] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Data = ArrayBuffer 4 | 5 | export function readData(bc: bare.ByteCursor): Data 6 | 7 | export function writeData(bc: bare.ByteCursor, x: Data): void 8 | 9 | export function encodeData(x: Data, config?: Partial): Uint8Array 10 | 11 | export function decodeData(bytes: Uint8Array): Data 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed/out.gen.js: -------------------------------------------------------------------------------- 1 | import assert from "node:assert/strict" 2 | import * as bare from "@bare-ts/lib" 3 | 4 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 5 | 6 | export function readData(bc) { 7 | return bare.readFixedData(bc, 16) 8 | } 9 | 10 | export function writeData(bc, x) { 11 | assert(x.byteLength === 16) 12 | bare.writeFixedData(bc, x) 13 | } 14 | 15 | export function encodeData(x, config) { 16 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 17 | const bc = new bare.ByteCursor( 18 | new Uint8Array(fullConfig.initialBufferLength), 19 | fullConfig, 20 | ) 21 | writeData(bc, x) 22 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 23 | } 24 | 25 | export function decodeData(bytes) { 26 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 27 | const result = readData(bc) 28 | if (bc.offset < bc.view.byteLength) { 29 | throw new bare.BareError(bc.offset, "remaining bytes") 30 | } 31 | return result 32 | } 33 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data-fixed/schema.bare: -------------------------------------------------------------------------------- 1 | type Data data[16] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Data", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "data", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 10 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "data/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Data data -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Data = ArrayBuffer 4 | 5 | export function readData(bc: bare.ByteCursor): Data 6 | 7 | export function writeData(bc: bare.ByteCursor, x: Data): void 8 | 9 | export function encodeData(x: Data, config?: Partial): Uint8Array 10 | 11 | export function decodeData(bytes: Uint8Array): Data 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readData(bc) { 6 | return bare.readData(bc) 7 | } 8 | 9 | export function writeData(bc, x) { 10 | bare.writeData(bc, x) 11 | } 12 | 13 | export function encodeData(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeData(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeData(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readData(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/data/schema.bare: -------------------------------------------------------------------------------- 1 | type Data data -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-anonymous/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | gender: enum { 4 | FLUID = 0 5 | MALE = 1 6 | FEMALE = 2 7 | } 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-anonymous/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Person = { 4 | readonly name: string 5 | readonly gender: "Fluid" | "Male" | "Female" 6 | } 7 | 8 | export function readPerson(bc: bare.ByteCursor): Person 9 | 10 | export function writePerson(bc: bare.ByteCursor, x: Person): void 11 | 12 | export function encodePerson(x: Person, config?: Partial): Uint8Array 13 | 14 | export function decodePerson(bytes: Uint8Array): Person 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-anonymous/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | gender: enum { 4 | FLUID 5 | MALE 6 | FEMALE 7 | } 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-big-val/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Male", 12 | "val": 1, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Female", 19 | "val": 2, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 36 23 | }, 24 | { 25 | "name": "Fluid", 26 | "val": 9007199254740991, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 51 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-big-val/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-big-val/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | MALE = 1 3 | FEMALE = 2 4 | FLUID = 9007199254740991 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-big-val/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Male = "Male", 5 | Female = "Female", 6 | Fluid = "Fluid", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-big-val/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | MALE = 1 3 | FEMALE = 2 4 | FLUID = 9007199254740991 # this is Number.MAX_SAFE_INTEGER 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-doccomment/out.gen.bare: -------------------------------------------------------------------------------- 1 | # An enum to model Genders 2 | type Gender enum { 3 | # Be inclusive :) 4 | FLUID = 0 5 | MALE = 1 6 | # One is not born, but becomes a woman 7 | # -- Simone de Beauvoir 8 | FEMALE = 2 9 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-doccomment/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | /** 4 | * An enum to model Genders 5 | */ 6 | export declare enum Gender { 7 | /** 8 | * Be inclusive :) 9 | */ 10 | Fluid = "Fluid", 11 | Male = "Male", 12 | /** 13 | * One is not born, but becomes a woman 14 | * -- Simone de Beauvoir 15 | */ 16 | Female = "Female", 17 | } 18 | 19 | export function readGender(bc: bare.ByteCursor): Gender 20 | 21 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 22 | 23 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 24 | 25 | export function decodeGender(bytes: Uint8Array): Gender 26 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-doccomment/schema.bare: -------------------------------------------------------------------------------- 1 | # An enum to model Genders 2 | type Gender enum { 3 | # Be inclusive :) 4 | FLUID 5 | MALE 6 | # One is not born, but becomes a woman 7 | # -- Simone de Beauvoir 8 | FEMALE 9 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int-anonymous/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useIntEnum": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int-anonymous/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | gender: enum { 4 | FLUID = 0 5 | MALE = 1 6 | FEMALE = 2 7 | } 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int-anonymous/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Person = { 4 | readonly name: string 5 | readonly gender: 0 | 1 | 2 6 | } 7 | 8 | export function readPerson(bc: bare.ByteCursor): Person 9 | 10 | export function writePerson(bc: bare.ByteCursor, x: Person): void 11 | 12 | export function encodePerson(x: Person, config?: Partial): Uint8Array 13 | 14 | export function decodePerson(bytes: Uint8Array): Person 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int-anonymous/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | gender: enum { 4 | FLUID 5 | MALE 6 | FEMALE 7 | } 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "type": { 7 | "tag": "enum", 8 | "data": [ 9 | { 10 | "name": "Fluid", 11 | "val": 0, 12 | "comment": "", 13 | "extra": null, 14 | "offset": 23 15 | }, 16 | { 17 | "name": "Male", 18 | "val": 1, 19 | "comment": "", 20 | "extra": null, 21 | "offset": 33 22 | }, 23 | { 24 | "name": "Female", 25 | "val": 2, 26 | "comment": "", 27 | "extra": null, 28 | "offset": 42 29 | } 30 | ], 31 | "types": null, 32 | "extra": { 33 | "intEnum": true 34 | }, 35 | "offset": 12 36 | }, 37 | "comment": "", 38 | "offset": 0 39 | } 40 | ], 41 | "filename": "enum-int/schema.bare", 42 | "offset": 0 43 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useIntEnum": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = 0, 5 | Male = 1, 6 | Female = 2, 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-int/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Fluid", 12 | "val": 0, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 18 16 | }, 17 | { 18 | "name": "Male", 19 | "val": 1, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 28 23 | }, 24 | { 25 | "name": "Female", 26 | "val": 2, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 37 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-legacy/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = "Fluid", 5 | Male = "Male", 6 | Female = "Female", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | enum Gender { 2 | FLUID 3 | MALE 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-partial-val/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Fluid", 12 | "val": 0, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Male", 19 | "val": 3, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 33 23 | }, 24 | { 25 | "name": "Female", 26 | "val": 4, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 46 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-partial-val/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-partial-val/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 3 4 | FEMALE = 4 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-partial-val/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = "Fluid", 5 | Male = "Male", 6 | Female = "Female", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-partial-val/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE = 3 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-val-pedantic/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Fluid", 12 | "val": 0, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Male", 19 | "val": 1, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 37 23 | }, 24 | { 25 | "name": "Female", 26 | "val": 2, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 50 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum-val-pedantic/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-val-pedantic/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pedantic": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-val-pedantic/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-val-pedantic/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = "Fluid", 5 | Male = "Male", 6 | Female = "Female", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum-val-pedantic/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Gender", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "enum", 9 | "data": [ 10 | { 11 | "name": "Fluid", 12 | "val": 0, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 23 16 | }, 17 | { 18 | "name": "Male", 19 | "val": 1, 20 | "comment": "", 21 | "extra": null, 22 | "offset": 33 23 | }, 24 | { 25 | "name": "Female", 26 | "val": 2, 27 | "comment": "", 28 | "extra": null, 29 | "offset": 42 30 | } 31 | ], 32 | "types": null, 33 | "extra": null, 34 | "offset": 12 35 | }, 36 | "offset": 0 37 | } 38 | ], 39 | "filename": "enum/schema.bare", 40 | "offset": 0 41 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = "Fluid", 5 | Male = "Male", 6 | Female = "Female", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export function encodeGender(x: Gender, config?: Partial): Uint8Array 14 | 15 | export function decodeGender(bytes: Uint8Array): Gender 16 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/enum/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE 4 | FEMALE 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Message", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "u8", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 13 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "imported-config/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "importConfig": true, 3 | "main": ["Message"] 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/ext.d.ts: -------------------------------------------------------------------------------- 1 | import * as _bare from "@bare-ts/lib" 2 | 3 | export const config: _bare.Config 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Message u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Message = u8 6 | 7 | export function readMessage(bc: bare.ByteCursor): Message 8 | 9 | export function writeMessage(bc: bare.ByteCursor, x: Message): void 10 | 11 | export function encodeMessage(x: Message, config?: Partial): Uint8Array 12 | 13 | export function decodeMessage(bytes: Uint8Array): Message 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readMessage(bc) { 6 | return bare.readU8(bc) 7 | } 8 | 9 | export function writeMessage(bc, x) { 10 | bare.writeU8(bc, x) 11 | } 12 | 13 | export function encodeMessage(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeMessage(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeMessage(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readMessage(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/imported-config/schema.bare: -------------------------------------------------------------------------------- 1 | type Message u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "alias", 13 | "data": "Alias", 14 | "types": null, 15 | "extra": null, 16 | "offset": 16 17 | } 18 | ], 19 | "extra": null, 20 | "offset": 11 21 | }, 22 | "offset": 0 23 | } 24 | ], 25 | "filename": "list-circular-ref/schema.bare", 26 | "offset": 0 27 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = readonly Alias[] 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias 6 | 7 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 8 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export function readAlias(bc) { 4 | const len = bare.readUintSafe(bc) 5 | if (len === 0) { 6 | return [] 7 | } 8 | const result = [readAlias(bc)] 9 | for (let i = 1; i < len; i++) { 10 | result[i] = readAlias(bc) 11 | } 12 | return result 13 | } 14 | 15 | export function writeAlias(bc, x) { 16 | bare.writeUintSafe(bc, x.length) 17 | for (let i = 0; i < x.length; i++) { 18 | writeAlias(bc, x[i]) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/out.gen.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = readonly Alias[] 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias { 6 | const len = bare.readUintSafe(bc) 7 | if (len === 0) { 8 | return [] 9 | } 10 | const result = [readAlias(bc)] 11 | for (let i = 1; i < len; i++) { 12 | result[i] = readAlias(bc) 13 | } 14 | return result 15 | } 16 | 17 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void { 18 | bare.writeUintSafe(bc, x.length) 19 | for (let i = 0; i < x.length; i++) { 20 | writeAlias(bc, x[i]) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-circular-ref/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-leading-0/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Array", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": { 10 | "name": null, 11 | "val": 4, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 22 15 | }, 16 | "types": [ 17 | { 18 | "tag": "u8", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 18 23 | } 24 | ], 25 | "extra": null, 26 | "offset": 13 27 | }, 28 | "offset": 0 29 | } 30 | ], 31 | "filename": "list-fixed-leading-0/schema.bare", 32 | "offset": 0 33 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-leading-0/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useGenericArray": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-leading-0/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-leading-0/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Array = readonly u8[] 6 | 7 | export function readU8Array(bc: bare.ByteCursor): U8Array 8 | 9 | export function writeU8Array(bc: bare.ByteCursor, x: U8Array): void 10 | 11 | export function encodeU8Array(x: U8Array, config?: Partial): Uint8Array 12 | 13 | export function decodeU8Array(bytes: Uint8Array): U8Array 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-leading-0/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[004] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Array", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": { 10 | "name": null, 11 | "val": 4, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 14 15 | }, 16 | "types": [ 17 | { 18 | "tag": "u8", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 16 23 | } 24 | ], 25 | "extra": null, 26 | "offset": 13 27 | }, 28 | "offset": 0 29 | } 30 | ], 31 | "filename": "list-fixed-legacy/schema.bare", 32 | "offset": 0 33 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true, 3 | "useGenericArray": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Array = readonly u8[] 6 | 7 | export function readU8Array(bc: bare.ByteCursor): U8Array 8 | 9 | export function writeU8Array(bc: bare.ByteCursor, x: U8Array): void 10 | 11 | export function encodeU8Array(x: U8Array, config?: Partial): Uint8Array 12 | 13 | export function decodeU8Array(bytes: Uint8Array): U8Array 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array [4]u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Array", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": { 10 | "name": null, 11 | "val": 4, 12 | "comment": null, 13 | "extra": null, 14 | "offset": 22 15 | }, 16 | "types": [ 17 | { 18 | "tag": "u8", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 18 23 | } 24 | ], 25 | "extra": null, 26 | "offset": 13 27 | }, 28 | "offset": 0 29 | } 30 | ], 31 | "filename": "list-fixed/schema.bare", 32 | "offset": 0 33 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useGenericArray": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8Array = readonly u8[] 6 | 7 | export function readU8Array(bc: bare.ByteCursor): U8Array 8 | 9 | export function writeU8Array(bc: bare.ByteCursor, x: U8Array): void 10 | 11 | export function encodeU8Array(x: U8Array, config?: Partial): Uint8Array 12 | 13 | export function decodeU8Array(bytes: Uint8Array): U8Array 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-fixed/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8List", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "u8", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 14 17 | } 18 | ], 19 | "extra": null, 20 | "offset": 12 21 | }, 22 | "offset": 0 23 | } 24 | ], 25 | "filename": "list-legacy/schema.bare", 26 | "offset": 0 27 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true, 3 | "useGenericArray": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8List list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8List = readonly u8[] 6 | 7 | export function readU8List(bc: bare.ByteCursor): U8List 8 | 9 | export function writeU8List(bc: bare.ByteCursor, x: U8List): void 10 | 11 | export function encodeU8List(x: U8List, config?: Partial): Uint8Array 12 | 13 | export function decodeU8List(bytes: Uint8Array): U8List 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type U8List []u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-union-circular-ref/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-union-circular-ref/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias list[2] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-union-circular-ref/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = readonly ( 4 | | { readonly tag: "Alias"; readonly val: Alias } 5 | | { readonly tag: 1; readonly val: string })[] 6 | 7 | export function readAlias(bc: bare.ByteCursor): Alias 8 | 9 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list-union-circular-ref/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias list[2] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8List", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "list", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "u8", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 17 17 | } 18 | ], 19 | "extra": null, 20 | "offset": 12 21 | }, 22 | "offset": 0 23 | } 24 | ], 25 | "filename": "list/schema.bare", 26 | "offset": 0 27 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useGenericArray": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8List list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8List = readonly u8[] 6 | 7 | export function readU8List(bc: bare.ByteCursor): U8List 8 | 9 | export function writeU8List(bc: bare.ByteCursor, x: U8List): void 10 | 11 | export function encodeU8List(x: U8List, config?: Partial): Uint8Array 12 | 13 | export function decodeU8List(bytes: Uint8Array): U8List 14 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/list/schema.bare: -------------------------------------------------------------------------------- 1 | type U8List list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "map", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "str", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 15 17 | }, 18 | { 19 | "tag": "alias", 20 | "data": "Alias", 21 | "types": null, 22 | "extra": null, 23 | "offset": 20 24 | } 25 | ], 26 | "extra": null, 27 | "offset": 11 28 | }, 29 | "offset": 0 30 | } 31 | ], 32 | "filename": "map-circular-ref/schema.bare", 33 | "offset": 0 34 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = ReadonlyMap 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias 6 | 7 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 8 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export function readAlias(bc) { 4 | const len = bare.readUintSafe(bc) 5 | const result = new Map() 6 | for (let i = 0; i < len; i++) { 7 | const offset = bc.offset 8 | const key = bare.readString(bc) 9 | if (result.has(key)) { 10 | bc.offset = offset 11 | throw new bare.BareError(offset, "duplicated key") 12 | } 13 | result.set(key, readAlias(bc)) 14 | } 15 | return result 16 | } 17 | 18 | export function writeAlias(bc, x) { 19 | bare.writeUintSafe(bc, x.size) 20 | for (const kv of x) { 21 | bare.writeString(bc, kv[0]) 22 | writeAlias(bc, kv[1]) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/out.gen.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = ReadonlyMap 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias { 6 | const len = bare.readUintSafe(bc) 7 | const result = new Map() 8 | for (let i = 0; i < len; i++) { 9 | const offset = bc.offset 10 | const key = bare.readString(bc) 11 | if (result.has(key)) { 12 | bc.offset = offset 13 | throw new bare.BareError(offset, "duplicated key") 14 | } 15 | result.set(key, readAlias(bc)) 16 | } 17 | return result 18 | } 19 | 20 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void { 21 | bare.writeUintSafe(bc, x.size) 22 | for (const kv of x) { 23 | bare.writeString(bc, kv[0]) 24 | writeAlias(bc, kv[1]) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-circular-ref/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-alias/out.gen.bare: -------------------------------------------------------------------------------- 1 | type KeyType str 2 | 3 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-alias/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type KeyType = string 4 | 5 | export function readKeyType(bc: bare.ByteCursor): KeyType 6 | 7 | export function writeKeyType(bc: bare.ByteCursor, x: KeyType): void 8 | 9 | export type Dict = ReadonlyMap 10 | 11 | export function readDict(bc: bare.ByteCursor): Dict 12 | 13 | export function writeDict(bc: bare.ByteCursor, x: Dict): void 14 | 15 | export function encodeDict(x: Dict, config?: Partial): Uint8Array 16 | 17 | export function decodeDict(bytes: Uint8Array): Dict 18 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-alias/schema.bare: -------------------------------------------------------------------------------- 1 | type KeyType str 2 | 3 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-data/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Dict", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "map", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "data", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 14 17 | }, 18 | { 19 | "tag": "str", 20 | "data": null, 21 | "types": null, 22 | "extra": null, 23 | "offset": 20 24 | } 25 | ], 26 | "extra": null, 27 | "offset": 10 28 | }, 29 | "offset": 0 30 | } 31 | ], 32 | "filename": "map-key-data/schema.bare", 33 | "offset": 0 34 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-data/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "noMain": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-data/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-data/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Dict = ReadonlyMap 4 | 5 | export function readDict(bc: bare.ByteCursor): Dict 6 | 7 | export function writeDict(bc: bare.ByteCursor, x: Dict): void 8 | 9 | export function encodeDict(x: Dict, config?: Partial): Uint8Array 10 | 11 | export function decodeDict(bytes: Uint8Array): Dict 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-data/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-enum/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID = 0 3 | MALE = 1 4 | FEMALE = 2 5 | } 6 | 7 | type GenderNames map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-enum/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare enum Gender { 4 | Fluid = "Fluid", 5 | Male = "Male", 6 | Female = "Female", 7 | } 8 | 9 | export function readGender(bc: bare.ByteCursor): Gender 10 | 11 | export function writeGender(bc: bare.ByteCursor, x: Gender): void 12 | 13 | export type GenderNames = ReadonlyMap 14 | 15 | export function readGenderNames(bc: bare.ByteCursor): GenderNames 16 | 17 | export function writeGenderNames(bc: bare.ByteCursor, x: GenderNames): void 18 | 19 | export function encodeGenderNames(x: GenderNames, config?: Partial): Uint8Array 20 | 21 | export function decodeGenderNames(bytes: Uint8Array): GenderNames 22 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-key-enum/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FLUID 3 | MALE 4 | FEMALE 5 | } 6 | 7 | type GenderNames map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Dict", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "map", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "str", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 14 17 | }, 18 | { 19 | "tag": "str", 20 | "data": null, 21 | "types": null, 22 | "extra": null, 23 | "offset": 19 24 | } 25 | ], 26 | "extra": null, 27 | "offset": 10 28 | }, 29 | "offset": 0 30 | } 31 | ], 32 | "filename": "map-legacy/schema.bare", 33 | "offset": 0 34 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Dict = ReadonlyMap 4 | 5 | export function readDict(bc: bare.ByteCursor): Dict 6 | 7 | export function writeDict(bc: bare.ByteCursor, x: Dict): void 8 | 9 | export function encodeDict(x: Dict, config?: Partial): Uint8Array 10 | 11 | export function decodeDict(bytes: Uint8Array): Dict 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map[str] str -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Dict", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "map", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "str", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 14 17 | }, 18 | { 19 | "tag": "str", 20 | "data": null, 21 | "types": null, 22 | "extra": null, 23 | "offset": 19 24 | } 25 | ], 26 | "extra": null, 27 | "offset": 10 28 | }, 29 | "offset": 0 30 | } 31 | ], 32 | "filename": "map/schema.bare", 33 | "offset": 0 34 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Dict = ReadonlyMap 4 | 5 | export function readDict(bc: bare.ByteCursor): Dict 6 | 7 | export function writeDict(bc: bare.ByteCursor, x: Dict): void 8 | 9 | export function encodeDict(x: Dict, config?: Partial): Uint8Array 10 | 11 | export function decodeDict(bytes: Uint8Array): Dict 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/map/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/multi-list-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true, 3 | "useGenericArray": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/multi-list-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type MultiList list>> -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/multi-list-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type MultiList = readonly (readonly (readonly string[])[])[] 4 | 5 | export function readMultiList(bc: bare.ByteCursor): MultiList 6 | 7 | export function writeMultiList(bc: bare.ByteCursor, x: MultiList): void 8 | 9 | export function encodeMultiList(x: MultiList, config?: Partial): Uint8Array 10 | 11 | export function decodeMultiList(bytes: Uint8Array): MultiList 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/multi-list-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type MultiList [][][]str -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/mutable-map/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Dict", 5 | "internal": false, 6 | "type": { 7 | "tag": "map", 8 | "data": null, 9 | "types": [ 10 | { 11 | "tag": "str", 12 | "data": null, 13 | "types": null, 14 | "extra": null, 15 | "offset": 14 16 | }, 17 | { 18 | "tag": "str", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 19 23 | } 24 | ], 25 | "extra": { 26 | "mut": true 27 | }, 28 | "offset": 10 29 | }, 30 | "comment": "", 31 | "offset": 0 32 | } 33 | ], 34 | "filename": "mutable-map/schema.bare", 35 | "offset": 0 36 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/mutable-map/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useMutable": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/mutable-map/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/mutable-map/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Dict = Map 4 | 5 | export function readDict(bc: bare.ByteCursor): Dict 6 | 7 | export function writeDict(bc: bare.ByteCursor, x: Dict): void 8 | 9 | export function encodeDict(x: Dict, config?: Partial): Uint8Array 10 | 11 | export function decodeDict(bytes: Uint8Array): Dict 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/mutable-map/schema.bare: -------------------------------------------------------------------------------- 1 | type Dict map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash-mutable/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Map", 5 | "internal": false, 6 | "type": { 7 | "tag": "map", 8 | "data": null, 9 | "types": [ 10 | { 11 | "tag": "str", 12 | "data": null, 13 | "types": null, 14 | "extra": null, 15 | "offset": 13 16 | }, 17 | { 18 | "tag": "str", 19 | "data": null, 20 | "types": null, 21 | "extra": null, 22 | "offset": 18 23 | } 24 | ], 25 | "extra": { 26 | "mut": true 27 | }, 28 | "offset": 9 29 | }, 30 | "comment": "", 31 | "offset": 0 32 | } 33 | ], 34 | "filename": "name-clash-mutable/schema.bare", 35 | "offset": 0 36 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash-mutable/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useMutable": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash-mutable/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Map map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash-mutable/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Map = globalThis.Map 4 | 5 | export function readMap(bc: bare.ByteCursor): Map 6 | 7 | export function writeMap(bc: bare.ByteCursor, x: Map): void 8 | 9 | export function encodeMap(x: Map, config?: Partial): Uint8Array 10 | 11 | export function decodeMap(bytes: Uint8Array): Map 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash-mutable/schema.bare: -------------------------------------------------------------------------------- 1 | type Map map -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash/out.gen.bare: -------------------------------------------------------------------------------- 1 | type ReadonlyMap map 2 | 3 | type Uint8Array list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type ReadonlyMap = globalThis.ReadonlyMap 4 | 5 | export function readReadonlyMap(bc: bare.ByteCursor): ReadonlyMap 6 | 7 | export function writeReadonlyMap(bc: bare.ByteCursor, x: ReadonlyMap): void 8 | 9 | export function encodeReadonlyMap(x: ReadonlyMap, config?: Partial): Uint8Array 10 | 11 | export function decodeReadonlyMap(bytes: Uint8Array): ReadonlyMap 12 | 13 | export type Uint8Array = globalThis.Uint8Array 14 | 15 | export function readUint8Array(bc: bare.ByteCursor): Uint8Array 16 | 17 | export function writeUint8Array(bc: bare.ByteCursor, x: Uint8Array): void 18 | 19 | export function encodeUint8Array(x: Uint8Array, config?: Partial): Uint8Array 20 | 21 | export function decodeUint8Array(bytes: Uint8Array): Uint8Array 22 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/name-clash/schema.bare: -------------------------------------------------------------------------------- 1 | type ReadonlyMap map 2 | type Uint8Array list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Alias", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "optional", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "alias", 13 | "data": "Alias", 14 | "types": null, 15 | "extra": null, 16 | "offset": 20 17 | } 18 | ], 19 | "extra": null, 20 | "offset": 11 21 | }, 22 | "offset": 0 23 | } 24 | ], 25 | "filename": "optional-circular/schema.bare", 26 | "offset": 0 27 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = null 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias 6 | 7 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 8 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export function readAlias(bc) { 4 | return bare.readBool(bc) ? readAlias(bc) : null 5 | } 6 | 7 | export function writeAlias(bc, x) { 8 | bare.writeBool(bc, x != null) 9 | if (x != null) { 10 | writeAlias(bc, x) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/out.gen.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = null 4 | 5 | export function readAlias(bc: bare.ByteCursor): Alias { 6 | return bare.readBool(bc) ? readAlias(bc) : null 7 | } 8 | 9 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void { 10 | bare.writeBool(bc, x != null) 11 | if (x != null) { 12 | writeAlias(bc, x) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-undefined/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "MaybeBool", 5 | "internal": false, 6 | "type": { 7 | "tag": "optional", 8 | "data": null, 9 | "types": [ 10 | { 11 | "tag": "bool", 12 | "data": null, 13 | "types": null, 14 | "extra": null, 15 | "offset": 24 16 | } 17 | ], 18 | "extra": { 19 | "literal": { 20 | "type": "undefined", 21 | "val": null 22 | } 23 | }, 24 | "offset": 15 25 | }, 26 | "comment": "", 27 | "offset": 0 28 | } 29 | ], 30 | "filename": "optional-undefined/schema.bare", 31 | "offset": 0 32 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-undefined/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useUndefined": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-undefined/out.gen.bare: -------------------------------------------------------------------------------- 1 | type MaybeBool optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-undefined/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type MaybeBool = boolean | undefined 4 | 5 | export function readMaybeBool(bc: bare.ByteCursor): MaybeBool 6 | 7 | export function writeMaybeBool(bc: bare.ByteCursor, x: MaybeBool): void 8 | 9 | export function encodeMaybeBool(x: MaybeBool, config?: Partial): Uint8Array 10 | 11 | export function decodeMaybeBool(bytes: Uint8Array): MaybeBool 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-undefined/schema.bare: -------------------------------------------------------------------------------- 1 | type MaybeBool optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-union-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-union-circular/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-union-circular/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = 4 | | { readonly tag: "Alias"; readonly val: Alias } 5 | | { readonly tag: 1; readonly val: string } | null 6 | 7 | export function readAlias(bc: bare.ByteCursor): Alias 8 | 9 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional-union-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "MaybeBool", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "optional", 9 | "data": null, 10 | "types": [ 11 | { 12 | "tag": "bool", 13 | "data": null, 14 | "types": null, 15 | "extra": null, 16 | "offset": 24 17 | } 18 | ], 19 | "extra": null, 20 | "offset": 15 21 | }, 22 | "offset": 0 23 | } 24 | ], 25 | "filename": "optional/schema.bare", 26 | "offset": 0 27 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional/out.gen.bare: -------------------------------------------------------------------------------- 1 | type MaybeBool optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type MaybeBool = boolean | null 4 | 5 | export function readMaybeBool(bc: bare.ByteCursor): MaybeBool 6 | 7 | export function writeMaybeBool(bc: bare.ByteCursor, x: MaybeBool): void 8 | 9 | export function encodeMaybeBool(x: MaybeBool, config?: Partial): Uint8Array 10 | 11 | export function decodeMaybeBool(bytes: Uint8Array): MaybeBool 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/optional/schema.bare: -------------------------------------------------------------------------------- 1 | type MaybeBool optional -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "AliasedVoid", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "void", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 17 13 | }, 14 | "offset": 0 15 | }, 16 | { 17 | "alias": "Main", 18 | "internal": false, 19 | "comment": "", 20 | "type": { 21 | "tag": "alias", 22 | "data": "AliasedVoid", 23 | "types": null, 24 | "extra": null, 25 | "offset": 32 26 | }, 27 | "offset": 22 28 | } 29 | ], 30 | "filename": "root-resolved-void/schema.bare", 31 | "offset": 0 32 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/out.gen.bare: -------------------------------------------------------------------------------- 1 | type AliasedVoid void 2 | 3 | type Main AliasedVoid -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | export type AliasedVoid = null 2 | 3 | export type Main = AliasedVoid 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/out.gen.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/out.gen.ts: -------------------------------------------------------------------------------- 1 | export type AliasedVoid = null 2 | 3 | export type Main = AliasedVoid 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-resolved-void/schema.bare: -------------------------------------------------------------------------------- 1 | type AliasedVoid void 2 | type Main AliasedVoid -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Main", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "void", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 10 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "root-void/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Main void -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | export type Main = null 2 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/out.gen.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/out.gen.ts: -------------------------------------------------------------------------------- 1 | export type Main = null 2 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/root-void/schema.bare: -------------------------------------------------------------------------------- 1 | type Main void -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U64List", 5 | "internal": false, 6 | "type": { 7 | "tag": "list", 8 | "data": null, 9 | "types": [ 10 | { 11 | "tag": "u64", 12 | "data": null, 13 | "types": null, 14 | "extra": { 15 | "safe": true 16 | }, 17 | "offset": 18 18 | } 19 | ], 20 | "extra": { 21 | "mut": false, 22 | "typedArray": true, 23 | "unique": false 24 | }, 25 | "offset": 13 26 | }, 27 | "comment": "", 28 | "offset": 0 29 | } 30 | ], 31 | "filename": "safe-int-list/schema.bare", 32 | "offset": 0 33 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useSafeInt": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U64List list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type U64List = BigUint64Array 4 | 5 | export function readU64List(bc: bare.ByteCursor): U64List 6 | 7 | export function writeU64List(bc: bare.ByteCursor, x: U64List): void 8 | 9 | export function encodeU64List(x: U64List, config?: Partial): Uint8Array 10 | 11 | export function decodeU64List(bytes: Uint8Array): U64List 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readU64List(bc) { 6 | return bare.readU64Array(bc) 7 | } 8 | 9 | export function writeU64List(bc, x) { 10 | bare.writeU64Array(bc, x) 11 | } 12 | 13 | export function encodeU64List(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeU64List(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeU64List(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readU64List(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int-list/schema.bare: -------------------------------------------------------------------------------- 1 | type U64List list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "I64", 5 | "internal": false, 6 | "type": { 7 | "tag": "i64", 8 | "data": null, 9 | "types": null, 10 | "extra": { 11 | "safe": true 12 | }, 13 | "offset": 9 14 | }, 15 | "comment": "", 16 | "offset": 0 17 | }, 18 | { 19 | "alias": "U64", 20 | "internal": false, 21 | "type": { 22 | "tag": "u64", 23 | "data": null, 24 | "types": null, 25 | "extra": { 26 | "safe": true 27 | }, 28 | "offset": 22 29 | }, 30 | "comment": "", 31 | "offset": 13 32 | } 33 | ], 34 | "filename": "safe-int/schema.bare", 35 | "offset": 0 36 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useSafeInt": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int/out.gen.bare: -------------------------------------------------------------------------------- 1 | type I64 i64 2 | 3 | type U64 u64 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type i64Safe = number 4 | export type u64Safe = number 5 | 6 | export type I64 = i64Safe 7 | 8 | export function readI64(bc: bare.ByteCursor): I64 9 | 10 | export function writeI64(bc: bare.ByteCursor, x: I64): void 11 | 12 | export function encodeI64(x: I64, config?: Partial): Uint8Array 13 | 14 | export function decodeI64(bytes: Uint8Array): I64 15 | 16 | export type U64 = u64Safe 17 | 18 | export function readU64(bc: bare.ByteCursor): U64 19 | 20 | export function writeU64(bc: bare.ByteCursor, x: U64): void 21 | 22 | export function encodeU64(x: U64, config?: Partial): Uint8Array 23 | 24 | export function decodeU64(bytes: Uint8Array): U64 25 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/safe-int/schema.bare: -------------------------------------------------------------------------------- 1 | type I64 i64 2 | type U64 u64 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "Name", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "str", 9 | "data": null, 10 | "types": null, 11 | "extra": null, 12 | "offset": 10 13 | }, 14 | "offset": 0 15 | } 16 | ], 17 | "filename": "string-legacy/schema.bare", 18 | "offset": 0 19 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Name str -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Name = string 4 | 5 | export function readName(bc: bare.ByteCursor): Name 6 | 7 | export function writeName(bc: bare.ByteCursor, x: Name): void 8 | 9 | export function encodeName(x: Name, config?: Partial): Uint8Array 10 | 11 | export function decodeName(bytes: Uint8Array): Name 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readName(bc) { 6 | return bare.readString(bc) 7 | } 8 | 9 | export function writeName(bc, x) { 10 | bare.writeString(bc, x) 11 | } 12 | 13 | export function encodeName(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeName(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeName(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readName(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/string-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type Name string -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-anonymous/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | address: struct { 5 | country: str 6 | city: struct { 7 | name: str 8 | code: u16 9 | } 10 | street: str 11 | } 12 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-anonymous/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | 6 | export type Person = { 7 | readonly name: string 8 | readonly age: u8 9 | readonly address: { 10 | readonly country: string 11 | readonly city: { 12 | readonly name: string 13 | readonly code: u16 14 | } 15 | readonly street: string 16 | } 17 | } 18 | 19 | export function readPerson(bc: bare.ByteCursor): Person 20 | 21 | export function writePerson(bc: bare.ByteCursor, x: Person): void 22 | 23 | export function encodePerson(x: Person, config?: Partial): Uint8Array 24 | 25 | export function decodePerson(bytes: Uint8Array): Person 26 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-anonymous/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | address: struct { 5 | country: str 6 | city: struct { 7 | name: str 8 | code: u16 9 | } 10 | street: str 11 | } 12 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-circular-ref-allowed/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-circular-ref-allowed/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | bestFriend: optional 3 | secondBestFriend: union { 4 | | Person = 0 5 | | void = 1 6 | } 7 | friends: list 8 | friendNicknames: map 9 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-circular-ref-allowed/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Person = { 4 | readonly bestFriend: Person | null 5 | readonly secondBestFriend: 6 | | { readonly tag: "Person"; readonly val: Person } 7 | | { readonly tag: 1; readonly val: null } 8 | readonly friends: readonly Person[] 9 | readonly friendNicknames: ReadonlyMap 10 | } 11 | 12 | export function readPerson(bc: bare.ByteCursor): Person 13 | 14 | export function writePerson(bc: bare.ByteCursor, x: Person): void 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-circular-ref-allowed/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | bestFriend: optional 3 | secondBestFriend: union{ Person | void } 4 | friends: list 5 | friendNicknames: map 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-class/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useClass": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-class/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-class/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export declare class Person { 6 | readonly name: string 7 | readonly age: u8 8 | constructor( 9 | name_: string, 10 | age_: u8, 11 | ) 12 | } 13 | 14 | export function readPerson(bc: bare.ByteCursor): Person 15 | 16 | export function writePerson(bc: bare.ByteCursor, x: Person): void 17 | 18 | export function encodePerson(x: Person, config?: Partial): Uint8Array 19 | 20 | export function decodePerson(bytes: Uint8Array): Person 21 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-class/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-doccomment/out.gen.bare: -------------------------------------------------------------------------------- 1 | # A struct to model persons 2 | type Person struct { 3 | # person's name 4 | name: str 5 | # person's age 6 | age: u8 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-doccomment/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | /** 6 | * A struct to model persons 7 | */ 8 | export type Person = { 9 | /** 10 | * person's name 11 | */ 12 | readonly name: string 13 | /** 14 | * person's age 15 | */ 16 | readonly age: u8 17 | } 18 | 19 | export function readPerson(bc: bare.ByteCursor): Person 20 | 21 | export function writePerson(bc: bare.ByteCursor, x: Person): void 22 | 23 | export function encodePerson(x: Person, config?: Partial): Uint8Array 24 | 25 | export function decodePerson(bytes: Uint8Array): Person 26 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-doccomment/schema.bare: -------------------------------------------------------------------------------- 1 | # A struct to model persons 2 | type Person struct { 3 | # person's name 4 | name: str 5 | # person's age 6 | age: u8 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-keyword-names/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Operation struct { 2 | type: str 3 | struct: str 4 | enum: str 5 | const: bool 6 | bc: u8 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-keyword-names/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Operation = { 6 | readonly type: string 7 | readonly struct: string 8 | readonly enum: string 9 | readonly const: boolean 10 | readonly bc: u8 11 | } 12 | 13 | export function readOperation(bc: bare.ByteCursor): Operation 14 | 15 | export function writeOperation(bc: bare.ByteCursor, x: Operation): void 16 | 17 | export function encodeOperation(x: Operation, config?: Partial): Uint8Array 18 | 19 | export function decodeOperation(bytes: Uint8Array): Operation 20 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-keyword-names/schema.bare: -------------------------------------------------------------------------------- 1 | type Operation struct { 2 | type: str 3 | struct: str 4 | enum: str 5 | const: bool 6 | bc: u8 7 | } 8 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Person = { 6 | readonly name: string 7 | readonly age: u8 8 | } 9 | 10 | export function readPerson(bc: bare.ByteCursor): Person 11 | 12 | export function writePerson(bc: bare.ByteCursor, x: Person): void 13 | 14 | export function encodePerson(x: Person, config?: Partial): Uint8Array 15 | 16 | export function decodePerson(bytes: Uint8Array): Person 17 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | struct Person { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-mutable/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useMutable": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-mutable/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-mutable/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Person = { 6 | name: string 7 | age: u8 8 | } 9 | 10 | export function readPerson(bc: bare.ByteCursor): Person 11 | 12 | export function writePerson(bc: bare.ByteCursor, x: Person): void 13 | 14 | export function encodePerson(x: Person, config?: Partial): Uint8Array 15 | 16 | export function decodePerson(bytes: Uint8Array): Person 17 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-mutable/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Node struct { 2 | children: list 3 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Node = { 4 | readonly children: readonly Node[] 5 | } 6 | 7 | export function readNode(bc: bare.ByteCursor): Node 8 | 9 | export function writeNode(bc: bare.ByteCursor, x: Node): void 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | function read0(bc) { 4 | const len = bare.readUintSafe(bc) 5 | if (len === 0) { 6 | return [] 7 | } 8 | const result = [readNode(bc)] 9 | for (let i = 1; i < len; i++) { 10 | result[i] = readNode(bc) 11 | } 12 | return result 13 | } 14 | 15 | function write0(bc, x) { 16 | bare.writeUintSafe(bc, x.length) 17 | for (let i = 0; i < x.length; i++) { 18 | writeNode(bc, x[i]) 19 | } 20 | } 21 | 22 | export function readNode(bc) { 23 | return { 24 | children: read0(bc), 25 | } 26 | } 27 | 28 | export function writeNode(bc, x) { 29 | write0(bc, x.children) 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/out.gen.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | function read0(bc: bare.ByteCursor): readonly Node[] { 4 | const len = bare.readUintSafe(bc) 5 | if (len === 0) { 6 | return [] 7 | } 8 | const result = [readNode(bc)] 9 | for (let i = 1; i < len; i++) { 10 | result[i] = readNode(bc) 11 | } 12 | return result 13 | } 14 | 15 | function write0(bc: bare.ByteCursor, x: readonly Node[]): void { 16 | bare.writeUintSafe(bc, x.length) 17 | for (let i = 0; i < x.length; i++) { 18 | writeNode(bc, x[i]) 19 | } 20 | } 21 | 22 | export type Node = { 23 | readonly children: readonly Node[] 24 | } 25 | 26 | export function readNode(bc: bare.ByteCursor): Node { 27 | return { 28 | children: read0(bc), 29 | } 30 | } 31 | 32 | export function writeNode(bc: bare.ByteCursor, x: Node): void { 33 | write0(bc, x.children) 34 | } 35 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-recursive/schema.bare: -------------------------------------------------------------------------------- 1 | type Node struct { 2 | children: list 3 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-reserved-js-names/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useClass": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-reserved-js-names/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Operation struct { 2 | await: str 3 | class: str 4 | extends: str 5 | typeof: str 6 | for: str 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-reserved-js-names/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export declare class Operation { 4 | readonly await: string 5 | readonly class: string 6 | readonly extends: string 7 | readonly typeof: string 8 | readonly for: string 9 | constructor( 10 | await_: string, 11 | class_: string, 12 | extends_: string, 13 | typeof_: string, 14 | for_: string, 15 | ) 16 | } 17 | 18 | export function readOperation(bc: bare.ByteCursor): Operation 19 | 20 | export function writeOperation(bc: bare.ByteCursor, x: Operation): void 21 | 22 | export function encodeOperation(x: Operation, config?: Partial): Uint8Array 23 | 24 | export function decodeOperation(bytes: Uint8Array): Operation 25 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct-reserved-js-names/schema.bare: -------------------------------------------------------------------------------- 1 | type Operation struct { 2 | await: str 3 | class: str 4 | extends: str 5 | typeof: str 6 | for: str 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Person = { 6 | readonly name: string 7 | readonly age: u8 8 | } 9 | 10 | export function readPerson(bc: bare.ByteCursor): Person 11 | 12 | export function writePerson(bc: bare.ByteCursor, x: Person): void 13 | 14 | export function encodePerson(x: Person, config?: Partial): Uint8Array 15 | 16 | export function decodePerson(bytes: Uint8Array): Person 17 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/struct/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | age: u8 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array-fixed/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Array", 5 | "internal": false, 6 | "type": { 7 | "tag": "list", 8 | "data": { 9 | "name": null, 10 | "val": 4, 11 | "comment": null, 12 | "extra": null, 13 | "offset": 22 14 | }, 15 | "types": [ 16 | { 17 | "tag": "u8", 18 | "data": null, 19 | "types": null, 20 | "extra": null, 21 | "offset": 18 22 | } 23 | ], 24 | "extra": { 25 | "mut": false, 26 | "typedArray": true, 27 | "unique": false 28 | }, 29 | "offset": 13 30 | }, 31 | "comment": "", 32 | "offset": 0 33 | } 34 | ], 35 | "filename": "typed-array-fixed/schema.bare", 36 | "offset": 0 37 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array-fixed/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array-fixed/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type U8Array = Uint8Array 4 | 5 | export function readU8Array(bc: bare.ByteCursor): U8Array 6 | 7 | export function writeU8Array(bc: bare.ByteCursor, x: U8Array): void 8 | 9 | export function encodeU8Array(x: U8Array, config?: Partial): Uint8Array 10 | 11 | export function decodeU8Array(bytes: Uint8Array): U8Array 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array-fixed/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array list[4] -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8Array", 5 | "internal": false, 6 | "type": { 7 | "tag": "list", 8 | "data": null, 9 | "types": [ 10 | { 11 | "tag": "u8", 12 | "data": null, 13 | "types": null, 14 | "extra": null, 15 | "offset": 18 16 | } 17 | ], 18 | "extra": { 19 | "mut": false, 20 | "typedArray": true, 21 | "unique": false 22 | }, 23 | "offset": 13 24 | }, 25 | "comment": "", 26 | "offset": 0 27 | } 28 | ], 29 | "filename": "typed-array/schema.bare", 30 | "offset": 0 31 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8Array list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type U8Array = Uint8Array 4 | 5 | export function readU8Array(bc: bare.ByteCursor): U8Array 6 | 7 | export function writeU8Array(bc: bare.ByteCursor, x: U8Array): void 8 | 9 | export function encodeU8Array(x: U8Array, config?: Partial): Uint8Array 10 | 11 | export function decodeU8Array(bytes: Uint8Array): U8Array 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array/out.gen.js: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({}) 4 | 5 | export function readU8Array(bc) { 6 | return bare.readU8Array(bc) 7 | } 8 | 9 | export function writeU8Array(bc, x) { 10 | bare.writeU8Array(bc, x) 11 | } 12 | 13 | export function encodeU8Array(x, config) { 14 | const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG 15 | const bc = new bare.ByteCursor( 16 | new Uint8Array(fullConfig.initialBufferLength), 17 | fullConfig, 18 | ) 19 | writeU8Array(bc, x) 20 | return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset) 21 | } 22 | 23 | export function decodeU8Array(bytes) { 24 | const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG) 25 | const result = readU8Array(bc) 26 | if (bc.offset < bc.view.byteLength) { 27 | throw new bare.BareError(bc.offset, "remaining bytes") 28 | } 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/typed-array/schema.bare: -------------------------------------------------------------------------------- 1 | type U8Array list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-big-tag/out.gen.bare: -------------------------------------------------------------------------------- 1 | # last tag is Number.MAX_SAFE_INTEGER 2 | type UnsignedInt union { 3 | | u8 = 0 4 | | u16 = 1 5 | | u32 = 2 6 | | u64 = 9007199254740991 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-big-tag/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | 8 | /** 9 | * last tag is Number.MAX_SAFE_INTEGER 10 | */ 11 | export type UnsignedInt = 12 | | { readonly tag: 0; readonly val: u8 } 13 | | { readonly tag: 1; readonly val: u16 } 14 | | { readonly tag: 2; readonly val: u32 } 15 | | { readonly tag: 9007199254740991; readonly val: u64 } 16 | 17 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 18 | 19 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 20 | 21 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 22 | 23 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 24 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-big-tag/schema.bare: -------------------------------------------------------------------------------- 1 | # last tag is Number.MAX_SAFE_INTEGER 2 | type UnsignedInt union { u8 = 0 | u16 = 1 | u32 = 2 | u64 = 9007199254740991 } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-circular/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias union { 2 | | Alias1 = 0 3 | | Alias2 = 1 4 | } 5 | 6 | type Alias1 Alias 7 | 8 | type Alias2 u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-circular/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Alias = 6 | | { readonly tag: "Alias1"; readonly val: Alias1 } 7 | | { readonly tag: "Alias2"; readonly val: Alias2 } 8 | 9 | export function readAlias(bc: bare.ByteCursor): Alias 10 | 11 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 12 | 13 | export type Alias1 = Alias 14 | 15 | export function readAlias1(bc: bare.ByteCursor): Alias1 16 | 17 | export function writeAlias1(bc: bare.ByteCursor, x: Alias1): void 18 | 19 | export type Alias2 = u8 20 | 21 | export function readAlias2(bc: bare.ByteCursor): Alias2 22 | 23 | export function writeAlias2(bc: bare.ByteCursor, x: Alias2): void 24 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias union { Alias1 | Alias2 } 2 | type Alias1 Alias 3 | type Alias2 u8 -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-composite-type/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Composite union { 2 | | map> = 0 3 | | list>[4] = 1 4 | | list[4] = 2 5 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-composite-type/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Composite = 4 | | { readonly tag: 0; readonly val: ReadonlyMap } 5 | | { readonly tag: 1; readonly val: readonly (string | null)[] } 6 | | { readonly tag: 2; readonly val: Uint8Array } 7 | 8 | export function readComposite(bc: bare.ByteCursor): Composite 9 | 10 | export function writeComposite(bc: bare.ByteCursor, x: Composite): void 11 | 12 | export function encodeComposite(x: Composite, config?: Partial): Uint8Array 13 | 14 | export function decodeComposite(bytes: Uint8Array): Composite 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-composite-type/schema.bare: -------------------------------------------------------------------------------- 1 | type Composite union { 2 | map> | list>[4] | list[4] 3 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-doccomment/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 3 6 | | uint = 4 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-doccomment/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | export type uint = bigint 8 | 9 | export type UnsignedInt = 10 | | { readonly tag: 0; readonly val: u8 } 11 | | { readonly tag: 1; readonly val: u16 } 12 | | { readonly tag: 2; readonly val: u32 } 13 | | { readonly tag: 3; readonly val: u64 } 14 | /** 15 | * Variable-length 16 | */ 17 | | { readonly tag: 4; readonly val: uint } 18 | 19 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 20 | 21 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 22 | 23 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 24 | 25 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 26 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-doccomment/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | u8 | 3 | u16 | 4 | u32 | 5 | u64 | 6 | # Variable-length 7 | uint | 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-anonymous-aliased-structs/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useStructFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-anonymous-aliased-structs/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Person struct { 2 | name: str 3 | } 4 | 5 | type Entity union { 6 | | Person = 0 7 | | struct { 8 | name: str 9 | } = 1 10 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-anonymous-aliased-structs/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Person = { 4 | readonly tag: "Person" 5 | readonly name: string 6 | } 7 | 8 | export function readPerson(bc: bare.ByteCursor): Person 9 | 10 | export function writePerson(bc: bare.ByteCursor, x: Person): void 11 | 12 | export type Entity = 13 | | Person 14 | /** 15 | * Anonymous entity 16 | */ 17 | | { 18 | readonly tag: 1 19 | readonly name: string 20 | } 21 | 22 | export function readEntity(bc: bare.ByteCursor): Entity 23 | 24 | export function writeEntity(bc: bare.ByteCursor, x: Entity): void 25 | 26 | export function encodeEntity(x: Entity, config?: Partial): Uint8Array 27 | 28 | export function decodeEntity(bytes: Uint8Array): Entity 29 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-anonymous-aliased-structs/schema.bare: -------------------------------------------------------------------------------- 1 | type Person struct { name: str } 2 | 3 | type Entity union { 4 | | Person 5 | # Anonymous entity 6 | | struct { name: str } 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-class/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useClass": true, 3 | "useStructFlatUnion": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-class/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { 10 | | BoxedU32 = 0 11 | | BoxedStr = 1 12 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-class/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export declare class BoxedU32 { 6 | readonly val: u32 7 | constructor( 8 | val_: u32, 9 | ) 10 | } 11 | 12 | export function readBoxedU32(bc: bare.ByteCursor): BoxedU32 13 | 14 | export function writeBoxedU32(bc: bare.ByteCursor, x: BoxedU32): void 15 | 16 | export declare class BoxedStr { 17 | readonly val: string 18 | constructor( 19 | val_: string, 20 | ) 21 | } 22 | 23 | export function readBoxedStr(bc: bare.ByteCursor): BoxedStr 24 | 25 | export function writeBoxedStr(bc: bare.ByteCursor, x: BoxedStr): void 26 | 27 | export type Boxed = 28 | | BoxedU32 29 | | BoxedStr 30 | 31 | export function readBoxed(bc: bare.ByteCursor): Boxed 32 | 33 | export function writeBoxed(bc: bare.ByteCursor, x: Boxed): void 34 | 35 | export function encodeBoxed(x: Boxed, config?: Partial): Uint8Array 36 | 37 | export function decodeBoxed(bytes: Uint8Array): Boxed 38 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-class/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { BoxedU32 | BoxedStr } 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-same-typeof/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "usePrimitiveFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-same-typeof/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 3 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-same-typeof/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | 8 | export type UnsignedInt = 9 | | { readonly tag: 0; readonly val: u8 } 10 | | { readonly tag: 1; readonly val: u16 } 11 | | { readonly tag: 2; readonly val: u32 } 12 | | { readonly tag: 3; readonly val: u64 } 13 | 14 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 15 | 16 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 17 | 18 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 19 | 20 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 21 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-same-typeof/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { u8 | u16 | u32 | u64 } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-anonymous/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useClass": true, 3 | "useStructFlatUnion": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-anonymous/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | struct { 3 | value: str 4 | } = 0 5 | | struct { 6 | value: u32 7 | } = 1 8 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-anonymous/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export type UnsignedInt = 6 | | { 7 | readonly tag: 0 8 | readonly value: string 9 | } 10 | | { 11 | readonly tag: 1 12 | readonly value: u32 13 | } 14 | 15 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 16 | 17 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 18 | 19 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 20 | 21 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 22 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-anonymous/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { struct { value: str } | struct { value: u32 } } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-tag-property/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useStructFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-tag-property/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | tag: str 3 | val: u32 4 | } 5 | 6 | type BoxedStr struct { 7 | val: str 8 | } 9 | 10 | type Boxed union { 11 | | BoxedU32 = 0 12 | | BoxedStr = 1 13 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-tag-property/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export type BoxedU32 = { 6 | readonly tag: string 7 | readonly val: u32 8 | } 9 | 10 | export function readBoxedU32(bc: bare.ByteCursor): BoxedU32 11 | 12 | export function writeBoxedU32(bc: bare.ByteCursor, x: BoxedU32): void 13 | 14 | export type BoxedStr = { 15 | readonly val: string 16 | } 17 | 18 | export function readBoxedStr(bc: bare.ByteCursor): BoxedStr 19 | 20 | export function writeBoxedStr(bc: bare.ByteCursor, x: BoxedStr): void 21 | 22 | export type Boxed = 23 | | { readonly tag: "BoxedU32"; readonly val: BoxedU32 } 24 | | { readonly tag: "BoxedStr"; readonly val: BoxedStr } 25 | 26 | export function readBoxed(bc: bare.ByteCursor): Boxed 27 | 28 | export function writeBoxed(bc: bare.ByteCursor, x: Boxed): void 29 | 30 | export function encodeBoxed(x: Boxed, config?: Partial): Uint8Array 31 | 32 | export function decodeBoxed(bytes: Uint8Array): Boxed 33 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct-tag-property/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | tag: str 3 | val: u32 4 | } 5 | 6 | type BoxedStr struct { 7 | val: str 8 | } 9 | 10 | type Boxed union { BoxedU32 | BoxedStr } 11 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useStructFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { 10 | | BoxedU32 = 0 11 | | BoxedStr = 1 12 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export type BoxedU32 = { 6 | readonly tag: "BoxedU32" 7 | readonly val: u32 8 | } 9 | 10 | export function readBoxedU32(bc: bare.ByteCursor): BoxedU32 11 | 12 | export function writeBoxedU32(bc: bare.ByteCursor, x: BoxedU32): void 13 | 14 | export type BoxedStr = { 15 | readonly tag: "BoxedStr" 16 | readonly val: string 17 | } 18 | 19 | export function readBoxedStr(bc: bare.ByteCursor): BoxedStr 20 | 21 | export function writeBoxedStr(bc: bare.ByteCursor, x: BoxedStr): void 22 | 23 | export type Boxed = 24 | | BoxedU32 25 | | BoxedStr 26 | 27 | export function readBoxed(bc: bare.ByteCursor): Boxed 28 | 29 | export function writeBoxed(bc: bare.ByteCursor, x: Boxed): void 30 | 31 | export function encodeBoxed(x: Boxed, config?: Partial): Uint8Array 32 | 33 | export function decodeBoxed(bytes: Uint8Array): Boxed 34 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-struct/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { BoxedU32 | BoxedStr } 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-transitive-alias/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useClass": true, 3 | "useStructFlatUnion": true 4 | } 5 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-transitive-alias/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type BoxedTransStr BoxedStr 10 | 11 | type Boxed union { 12 | | BoxedU32 = 0 13 | | BoxedTransStr = 1 14 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-transitive-alias/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type BoxedTransStr BoxedStr 10 | 11 | type Boxed union { BoxedU32 | BoxedTransStr } 12 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-typeof/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "usePrimitiveFlatUnion": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-typeof/out.gen.bare: -------------------------------------------------------------------------------- 1 | type TypeOfUnion union { 2 | | bool = 0 3 | | u32 = 1 4 | | str = 2 5 | | void = 3 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-typeof/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export type TypeOfUnion = 6 | | boolean 7 | | u32 8 | | string 9 | | null 10 | 11 | export function readTypeOfUnion(bc: bare.ByteCursor): TypeOfUnion 12 | 13 | export function writeTypeOfUnion(bc: bare.ByteCursor, x: TypeOfUnion): void 14 | 15 | export function encodeTypeOfUnion(x: TypeOfUnion, config?: Partial): Uint8Array 16 | 17 | export function decodeTypeOfUnion(bytes: Uint8Array): TypeOfUnion 18 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-flat-typeof/schema.bare: -------------------------------------------------------------------------------- 1 | type TypeOfUnion union { bool | u32 | str | void } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-leading-trailing-pipes/out.gen.bare: -------------------------------------------------------------------------------- 1 | type LeadingPipe union { 2 | | u8 = 0 3 | } 4 | 5 | type TrailingPipe union { 6 | | u8 = 0 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-leading-trailing-pipes/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type LeadingPipe = 6 | | { readonly tag: 0; readonly val: u8 } 7 | 8 | export function readLeadingPipe(bc: bare.ByteCursor): LeadingPipe 9 | 10 | export function writeLeadingPipe(bc: bare.ByteCursor, x: LeadingPipe): void 11 | 12 | export function encodeLeadingPipe(x: LeadingPipe, config?: Partial): Uint8Array 13 | 14 | export function decodeLeadingPipe(bytes: Uint8Array): LeadingPipe 15 | 16 | export type TrailingPipe = 17 | | { readonly tag: 0; readonly val: u8 } 18 | 19 | export function readTrailingPipe(bc: bare.ByteCursor): TrailingPipe 20 | 21 | export function writeTrailingPipe(bc: bare.ByteCursor, x: TrailingPipe): void 22 | 23 | export function encodeTrailingPipe(x: TrailingPipe, config?: Partial): Uint8Array 24 | 25 | export function decodeTrailingPipe(bytes: Uint8Array): TrailingPipe 26 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-leading-trailing-pipes/schema.bare: -------------------------------------------------------------------------------- 1 | type LeadingPipe union { 2 | | u8 3 | } 4 | 5 | type TrailingPipe union { 6 | u8 | 7 | } 8 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-legacy/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-legacy/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 3 6 | | uint = 4 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-legacy/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | export type uint = bigint 8 | 9 | export type UnsignedInt = 10 | | { readonly tag: 0; readonly val: u8 } 11 | | { readonly tag: 1; readonly val: u16 } 12 | | { readonly tag: 2; readonly val: u32 } 13 | | { readonly tag: 3; readonly val: u64 } 14 | | { readonly tag: 4; readonly val: uint } 15 | 16 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 17 | 18 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 19 | 20 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 21 | 22 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 23 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-legacy/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt (u8 | u16 | u32 | u64 | uint) -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-optional-circular/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "legacy": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-optional-circular/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Alias union { 2 | | optional = 0 3 | | str = 1 4 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-optional-circular/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type Alias = 4 | | { readonly tag: 0; readonly val: Alias | null } 5 | | { readonly tag: 1; readonly val: string } 6 | 7 | export function readAlias(bc: bare.ByteCursor): Alias 8 | 9 | export function writeAlias(bc: bare.ByteCursor, x: Alias): void 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-optional-circular/schema.bare: -------------------------------------------------------------------------------- 1 | type Alias union { optional | str } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-partial-tag/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 5 4 | | u32 = 6 5 | | u64 = 7 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-partial-tag/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | 8 | export type UnsignedInt = 9 | | { readonly tag: 0; readonly val: u8 } 10 | | { readonly tag: 5; readonly val: u16 } 11 | | { readonly tag: 6; readonly val: u32 } 12 | | { readonly tag: 7; readonly val: u64 } 13 | 14 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 15 | 16 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 17 | 18 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 19 | 20 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 21 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-partial-tag/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { u8 | u16 = 5 | u32 | u64 } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-repeated-aliased-type/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Y u8 2 | 3 | type X union { 4 | | u8 = 0 5 | | Y = 1 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-repeated-aliased-type/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type Y = u8 6 | 7 | export function readY(bc: bare.ByteCursor): Y 8 | 9 | export function writeY(bc: bare.ByteCursor, x: Y): void 10 | 11 | export type X = 12 | | { readonly tag: 0; readonly val: u8 } 13 | | { readonly tag: "Y"; readonly val: Y } 14 | 15 | export function readX(bc: bare.ByteCursor): X 16 | 17 | export function writeX(bc: bare.ByteCursor, x: X): void 18 | 19 | export function encodeX(x: X, config?: Partial): Uint8Array 20 | 21 | export function decodeX(bytes: Uint8Array): X 22 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-repeated-aliased-type/schema.bare: -------------------------------------------------------------------------------- 1 | type Y u8 2 | type X union { u8 | Y } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-singleton/ast.gen.json: -------------------------------------------------------------------------------- 1 | { 2 | "defs": [ 3 | { 4 | "alias": "U8", 5 | "internal": false, 6 | "comment": "", 7 | "type": { 8 | "tag": "union", 9 | "data": [ 10 | { 11 | "name": null, 12 | "val": 0, 13 | "comment": "", 14 | "extra": null, 15 | "offset": 19 16 | } 17 | ], 18 | "types": [ 19 | { 20 | "tag": "u8", 21 | "data": null, 22 | "types": null, 23 | "extra": null, 24 | "offset": 16 25 | } 26 | ], 27 | "extra": null, 28 | "offset": 8 29 | }, 30 | "offset": 0 31 | } 32 | ], 33 | "filename": "union-singleton/schema.bare", 34 | "offset": 0 35 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-singleton/out.gen.bare: -------------------------------------------------------------------------------- 1 | type U8 union { 2 | | u8 = 0 3 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-singleton/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | 5 | export type U8 = 6 | | { readonly tag: 0; readonly val: u8 } 7 | 8 | export function readU8(bc: bare.ByteCursor): U8 9 | 10 | export function writeU8(bc: bare.ByteCursor, x: U8): void 11 | 12 | export function encodeU8(x: U8, config?: Partial): Uint8Array 13 | 14 | export function decodeU8(bytes: Uint8Array): U8 15 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-singleton/schema.bare: -------------------------------------------------------------------------------- 1 | type U8 union { u8 } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-struct-int-tag/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useIntTag": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-struct-int-tag/out.gen.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { 10 | | BoxedU32 = 0 11 | | BoxedStr = 1 12 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-struct-int-tag/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u32 = number 4 | 5 | export type BoxedU32 = { 6 | readonly val: u32 7 | } 8 | 9 | export function readBoxedU32(bc: bare.ByteCursor): BoxedU32 10 | 11 | export function writeBoxedU32(bc: bare.ByteCursor, x: BoxedU32): void 12 | 13 | export type BoxedStr = { 14 | readonly val: string 15 | } 16 | 17 | export function readBoxedStr(bc: bare.ByteCursor): BoxedStr 18 | 19 | export function writeBoxedStr(bc: bare.ByteCursor, x: BoxedStr): void 20 | 21 | export type Boxed = 22 | | { readonly tag: 0; readonly val: BoxedU32 } 23 | | { readonly tag: 1; readonly val: BoxedStr } 24 | 25 | export function readBoxed(bc: bare.ByteCursor): Boxed 26 | 27 | export function writeBoxed(bc: bare.ByteCursor, x: Boxed): void 28 | 29 | export function encodeBoxed(x: Boxed, config?: Partial): Uint8Array 30 | 31 | export function decodeBoxed(bytes: Uint8Array): Boxed 32 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-struct-int-tag/schema.bare: -------------------------------------------------------------------------------- 1 | type BoxedU32 struct { 2 | val: u32 3 | } 4 | 5 | type BoxedStr struct { 6 | val: str 7 | } 8 | 9 | type Boxed union { BoxedU32 | BoxedStr } 10 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-tag-pedantic/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pedantic": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-tag-pedantic/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 99 6 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-tag-pedantic/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | 8 | export type UnsignedInt = 9 | | { readonly tag: 0; readonly val: u8 } 10 | | { readonly tag: 1; readonly val: u16 } 11 | | { readonly tag: 2; readonly val: u32 } 12 | | { readonly tag: 99; readonly val: u64 } 13 | 14 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 15 | 16 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 17 | 18 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 19 | 20 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 21 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-tag-pedantic/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { u8 = 0 | u16 = 1 | u32 = 2 | u64 = 99 } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-void/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 3 6 | | void = 4 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-void/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | 8 | export type UnsignedInt = 9 | | { readonly tag: 0; readonly val: u8 } 10 | | { readonly tag: 1; readonly val: u16 } 11 | | { readonly tag: 2; readonly val: u32 } 12 | | { readonly tag: 3; readonly val: u64 } 13 | | { readonly tag: 4; readonly val: null } 14 | 15 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 16 | 17 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 18 | 19 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 20 | 21 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 22 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union-void/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { u8 | u16 | u32 | u64 | void } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union/out.gen.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { 2 | | u8 = 0 3 | | u16 = 1 4 | | u32 = 2 5 | | u64 = 3 6 | | uint = 4 7 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union/out.gen.d.ts: -------------------------------------------------------------------------------- 1 | import * as bare from "@bare-ts/lib" 2 | 3 | export type u8 = number 4 | export type u16 = number 5 | export type u32 = number 6 | export type u64 = bigint 7 | export type uint = bigint 8 | 9 | export type UnsignedInt = 10 | | { readonly tag: 0; readonly val: u8 } 11 | | { readonly tag: 1; readonly val: u16 } 12 | | { readonly tag: 2; readonly val: u32 } 13 | | { readonly tag: 3; readonly val: u64 } 14 | | { readonly tag: 4; readonly val: uint } 15 | 16 | export function readUnsignedInt(bc: bare.ByteCursor): UnsignedInt 17 | 18 | export function writeUnsignedInt(bc: bare.ByteCursor, x: UnsignedInt): void 19 | 20 | export function encodeUnsignedInt(x: UnsignedInt, config?: Partial): Uint8Array 21 | 22 | export function decodeUnsignedInt(bytes: Uint8Array): UnsignedInt 23 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/union/schema.bare: -------------------------------------------------------------------------------- 1 | type UnsignedInt union { u8 | u16 | u32 | u64 | uint } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/x-bareorg-example/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "useSafeInt": true 3 | } 4 | -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/x-bareorg-example/out.gen.bare: -------------------------------------------------------------------------------- 1 | type PublicKey data[128] 2 | 3 | # ISO 8601 4 | type Time str 5 | 6 | type Department enum { 7 | ACCOUNTING = 0 8 | ADMINISTRATION = 1 9 | CUSTOMER_SERVICE = 2 10 | DEVELOPMENT = 3 11 | # Reserved for the CEO 12 | JSMITH = 99 13 | } 14 | 15 | type Address list[4] 16 | 17 | type Customer struct { 18 | name: str 19 | email: str 20 | address: Address 21 | orders: list 25 | metadata: map 26 | } 27 | 28 | type Employee struct { 29 | name: str 30 | email: str 31 | address: Address 32 | department: Department 33 | hireDate: Time 34 | publicKey: optional 35 | metadata: map 36 | } 37 | 38 | type TerminatedEmployee void 39 | 40 | type Person union { 41 | | Customer = 0 42 | | Employee = 1 43 | | TerminatedEmployee = 2 44 | } -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/x-bareorg-example/schema.bare: -------------------------------------------------------------------------------- 1 | type PublicKey data[128] 2 | 3 | # ISO 8601 4 | type Time str 5 | 6 | type Department enum { 7 | ACCOUNTING 8 | ADMINISTRATION 9 | CUSTOMER_SERVICE 10 | DEVELOPMENT 11 | 12 | # Reserved for the CEO 13 | JSMITH = 99 14 | } 15 | 16 | type Address list[4] 17 | 18 | type Customer struct { 19 | name: str 20 | email: str 21 | address: Address 22 | orders: list 26 | metadata: map 27 | } 28 | 29 | type Employee struct { 30 | name: str 31 | email: str 32 | address: Address 33 | department: Department 34 | hireDate: Time 35 | publicKey: optional 36 | metadata: map 37 | } 38 | 39 | type TerminatedEmployee void 40 | 41 | type Person union {Customer | Employee | TerminatedEmployee} -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/x-readme-example/out.gen.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FEMALE = 0 3 | FLUID = 1 4 | MALE = 2 5 | } 6 | 7 | type Person struct { 8 | name: str 9 | email: str 10 | gender: optional 11 | } 12 | 13 | type Organization struct { 14 | name: str 15 | email: str 16 | } 17 | 18 | type Contact union { 19 | | Person = 0 20 | | Organization = 1 21 | } 22 | 23 | type Contacts list -------------------------------------------------------------------------------- /tests-corpus/valid-bare-schema/x-readme-example/schema.bare: -------------------------------------------------------------------------------- 1 | type Gender enum { 2 | FEMALE 3 | FLUID 4 | MALE 5 | } 6 | 7 | type Person struct { 8 | name: str 9 | email: str 10 | gender: optional 11 | } 12 | 13 | type Organization struct { 14 | name: str 15 | email: str 16 | } 17 | 18 | type Contact union { Person | Organization } 19 | 20 | type Contacts list --------------------------------------------------------------------------------