Skip to content

Commit

Permalink
Fix ST object bugs (#196)
Browse files Browse the repository at this point in the history
* Fix ST object bugs

* bump
  • Loading branch information
lucasavila00 committed May 10, 2024
1 parent 2af1f20 commit 16f38c0
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 15 deletions.
8 changes: 8 additions & 0 deletions examples/standalone-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# node-server

## 1.0.41

### Patch Changes

- Updated dependencies
- @beff/cli@0.0.44
- @beff/client@0.0.44

## 1.0.40

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/standalone-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "standalone-parser",
"version": "1.0.40",
"version": "1.0.41",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@beff/cli": "workspace:^0.0.43",
"@beff/cli": "workspace:^0.0.44",
"@beff/client": "workspace:^",
"vitest": "^0.34.4",
"zod": "^3.23.5"
Expand Down
6 changes: 6 additions & 0 deletions packages/beff-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @beff/cli

## 0.0.44

### Patch Changes

- fix st obj bugs

## 0.0.43

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/beff-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beff/cli",
"version": "0.0.43",
"version": "0.0.44",
"description": "",
"bin": {
"beff": "./bin/index.js"
Expand Down
8 changes: 8 additions & 0 deletions packages/beff-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @beff/client

## 0.0.44

### Patch Changes

- fix st obj bugs
- Updated dependencies
- @beff/cli@0.0.44

## 0.0.43

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/beff-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beff/client",
"version": "0.0.43",
"version": "0.0.44",
"description": "",
"main": "dist/cjs/index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@beff/cli": "workspace:^0.0.43"
"@beff/cli": "workspace:^0.0.44"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.7.2",
Expand Down
1 change: 0 additions & 1 deletion packages/beff-core/src/subtyping/bdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ pub fn mapping_indexed_access(
_ => unreachable!("should be string"),
},
};

let b = SemTypeContext::sub_type_data(obj_st, SubTypeTag::Mapping);
match b {
SubType::False(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion packages/beff-core/src/subtyping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a> ToSemTypeConverter<'a> {
.collect::<Result<_>>()?;
let rest = match rest {
Some(r) => self.to_sem_type(r, builder)?,
None => SemTypeContext::never().into(),
None => SemTypeContext::unknown().into(),
};

builder.mapping_definitions[idx] = Some(Rc::new(MappingAtomicType {
Expand Down
2 changes: 2 additions & 0 deletions packages/beff-core/src/subtyping/semtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ impl MemoEmpty {
#[derive(Clone, Debug)]
pub struct BddMemoEmptyRef(pub MemoEmpty);

#[derive(Debug)]

pub struct MappingAtomicType {
pub vs: Rc<MappingAtomic>,
pub rest: Rc<SemType>,
Expand Down
7 changes: 4 additions & 3 deletions packages/beff-core/src/subtyping/to_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::{
rc::Rc,
};

use anyhow::bail;

use crate::{
ast::json_schema::{JsonSchema, JsonSchemaConst, Optionality},
Validator,
Expand Down Expand Up @@ -184,8 +186,7 @@ impl<'a, 'b> SchemerContext<'a, 'b> {
}

let rest = if mt.rest.is_empty(self.ctx.0) {
// bail!("rest should not be empty, all records are open")
None
bail!("rest should not be empty, all records are open")
} else if mt.rest.is_any() {
None
} else {
Expand Down Expand Up @@ -425,7 +426,7 @@ impl<'a, 'b> SchemerContext<'a, 'b> {
acc.insert(JsonSchema::String);
}
SubTypeTag::Void => {
// noop
acc.insert(JsonSchema::Null);
}
SubTypeTag::Mapping => {
acc.insert(JsonSchema::object(vec![], Some(JsonSchema::Any.into())));
Expand Down
2 changes: 1 addition & 1 deletion packages/beff-core/src/type_to_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ impl<'a, 'b, R: FileManager> TypeToSchema<'a, 'b, R> {
})?;

let access_st: Rc<SemType> = ctx.indexed_access(obj_st, idx_st);
self.convert_sem_type(access_st, &mut ctx, &i.index_type.span())
self.convert_sem_type(access_st, &mut ctx, &i.span())
}
fn convert_keyof(&mut self, k: &TsType) -> Res<JsonSchema> {
let json_schema = self.convert_ts_type(k)?;
Expand Down
15 changes: 15 additions & 0 deletions packages/beff-core/tests/print_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,19 @@ mod tests {
parse.buildParsers<{ T3: T3 }>();
"#));
}
#[test]
fn ok_repro_3() {
insta::assert_snapshot!(ok(r#"
export interface IY {
a: string
}
export interface IX {
sizes?: IY;
}
// type IX2 = Required<IX>
type T3 = IX[keyof IX]
parse.buildParsers<{ T3: T3 }>();
"#));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: packages/beff-core/tests/print_parser.rs
expression: "ok(r#\"\n \n export interface IY {\n a: string\n }\n export interface IX {\n sizes?: IY;\n }\n // type IX2 = Required<IX>\n type T3 = IX[keyof IX]\n parse.buildParsers<{ T3: T3 }>();\n \"#)"
---
type IX = { "sizes"?: IY };
type IY = { "a": string };
type T3 = null | { "a": string };
type T3 = T3;
2 changes: 1 addition & 1 deletion packages/beff-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@babel/code-frame": "^7.22.13",
"@beff/cli": "workspace:^0.0.43",
"@beff/cli": "workspace:^0.0.44",
"@types/babel__code-frame": "^7.0.4",
"@types/node": "^20.6.2",
"@types/vscode": "^1.73.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16f38c0

Please sign in to comment.