Skip to content

Commit

Permalink
rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertMarashi committed Sep 23, 2024
1 parent 057e8f4 commit 4cf5eac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

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

22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
# `surreal-codegen`
> [!WARNING]
> This is a work in progress, but we are currently using it in production at [Siteforge](https://siteforge.io) to help ensure type safety in our SurrealDB queries.
> This is a WIP, but we are currently using it in production at [Siteforge](https://siteforge.io) to help ensure type safety in our SurrealDB queries.
> See the [Features Supported](#features-supported) section for a list of features we currently support.
# Installation

> [!WARNING]
> We haven't currently setup a build automation system, so you must build the project yourself.
## NPM install
```sh
npm i -g @siteforge/surreal-codegen
```

## Manual Installation
### Cargo Install
```sh
cargo install --git https://github.com/siteforge-io/surreal-codegen.git
```
You must have the rust toolchain installed, then run:

### Via Git
1. Clone this repo
```sh
git clone https://github.com/siteforge-io/surreal-codegen.git
```

2. Build and install the binary
```sh
cargo install --path ./surreal-codegen
cargo install --git https://github.com/siteforge-io/surreal-codegen.git
```

## Running `surreal-codegen`
Expand Down Expand Up @@ -133,7 +125,7 @@ You can also define global parameters in a `global.surql` file, which will be av
- We only currently support SCHEMAFULL tables so far, but we are working on supporting other table types.


# Features Supported So Far
# Features Supported

### General Type Support and Handling
- [x] `Never`
Expand Down
2 changes: 1 addition & 1 deletion surreal-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
type_generator = { path = "../surreal_type_generator", version = "0.1.0" }
surreal_type_generator = { path = "../surreal_type_generator", version = "0.1.0" }
anyhow = "1.0.66"
clap = { version = "4.5.9", features = ["derive"] }
18 changes: 11 additions & 7 deletions surreal-codegen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
use type_generator::step_3_codegen::typescript::{generate_type_info, generate_typescript_output};
use surreal_type_generator::{step_1_parse_sql, step_2_interpret, step_3_codegen};

#[derive(Parser)]
struct Cli {
Expand Down Expand Up @@ -29,25 +29,29 @@ struct Cli {
pub fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

let mut files = type_generator::step_3_codegen::read_surql_files(&cli.dir)?;
let mut files = step_3_codegen::read_surql_files(&cli.dir)?;

let globals = if let Some(globals) = files.remove("globals.surql") {
type_generator::step_1_parse_sql::parse_value_casts(&globals)?
step_1_parse_sql::parse_value_casts(&globals)?
} else {
BTreeMap::new()
};

let schema = type_generator::step_3_codegen::read_file(&PathBuf::from(&cli.schema))?;
let state = type_generator::step_2_interpret::interpret_schema(&schema, globals)?;
let schema = step_3_codegen::read_file(&PathBuf::from(&cli.schema))?;
let state = step_2_interpret::interpret_schema(&schema, globals)?;
let state = Arc::new(state);

let mut types = Vec::new();

for (file_name, query) in files {
types.push(generate_type_info(&file_name, &query, state.clone())?);
types.push(step_3_codegen::typescript::generate_type_info(
&file_name,
&query,
state.clone(),
)?);
}

let output = generate_typescript_output(&types, &cli.header)?;
let output = step_3_codegen::typescript::generate_typescript_output(&types, &cli.header)?;

std::fs::write(cli.output, output)?;

Expand Down

0 comments on commit 4cf5eac

Please sign in to comment.