Skip to content

Commit

Permalink
Merge branch 'main' into qe-add-json-seriaization-span-in-binary-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln authored Apr 9, 2024
2 parents b4d32f5 + 87bc6b8 commit 81129cf
Show file tree
Hide file tree
Showing 232 changed files with 4,155 additions and 1,393 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v26
with:
# we need internet access for the moment
extra_nix_config: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-prisma-schema-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: echo "SLACK_FOOTER=<$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|Click here to go to the job logs>" >> $GITHUB_ENV
- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2.2.1
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_TITLE: 'Building and publishing @prisma/prisma-schema-wasm failed :x:'
SLACK_COLOR: '#FF0000'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-query-engine-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: echo "SLACK_FOOTER=<$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|Click here to go to the job logs>" >> $GITHUB_ENV
- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2.2.1
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_TITLE: "Building and publishing @prisma/query-engine-wasm failed :x:"
SLACK_COLOR: "#FF0000"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-query-engine-driver-adapters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
setup_task: "dev-neon-wasm"
- name: "libsql (wasm)"
setup_task: "dev-libsql-wasm"
- name: "d1 (wasm)"
setup_task: "dev-d1"
node_version: ["18"]
partition: ["1/4", "2/4", "3/4", "4/4"]
env:
Expand Down Expand Up @@ -68,7 +70,7 @@ jobs:
node-version: ${{ matrix.node_version }}

- name: "Setup pnpm"
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3.0.0
with:
version: 8

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/setup-node@v4

- name: "Setup pnpm"
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3.0.0
with:
version: 8

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wasm-size.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "QE: WASM size"
name: "QE: WASM Query Engine size"
on:
pull_request:
paths-ignore:
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- wasm-size -->
### WASM Size
### WASM Query Engine file Size
|Engine | This PR | Base branch | Diff
|------------------|----------------------------------------------|--------------------------------------------------|-----------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prisma-gpg-private.asc
.test_config
*.pending-snap
.pending.md
dev.db

*.class
*.log
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ dev-libsql-wasm: build-qe-wasm build-driver-adapters-kit
test-libsql-wasm: dev-libsql-wasm test-qe-st
test-driver-adapter-libsql-wasm: test-libsql-wasm

dev-d1: build-qe-wasm build-driver-adapters-kit
cp $(CONFIG_PATH)/cloudflare-d1 $(CONFIG_FILE)

test-d1: dev-d1 test-qe-st
test-driver-adapter-d1: test-d1

start-postgres9:
docker compose -f docker-compose.yml up --wait -d --remove-orphans postgres9

Expand Down
33 changes: 22 additions & 11 deletions prisma-fmt/src/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec

let datasource = config.datasources.first();

for source in validated_schema.db.ast().sources() {
relation_mode::edit_referential_integrity(&mut actions, &params, validated_schema.db.source(), source)
for source in validated_schema.db.ast_assert_single().sources() {
relation_mode::edit_referential_integrity(
&mut actions,
&params,
validated_schema.db.source_assert_single(),
source,
)
}

// models AND views
Expand All @@ -45,21 +50,27 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec
multi_schema::add_schema_block_attribute_model(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
config,
model,
);

multi_schema::add_schema_to_schemas(&mut actions, &params, validated_schema.db.source(), config, model);
multi_schema::add_schema_to_schemas(
&mut actions,
&params,
validated_schema.db.source_assert_single(),
config,
model,
);
}

if matches!(datasource, Some(ds) if ds.active_provider == "mongodb") {
mongodb::add_at_map_for_id(&mut actions, &params, validated_schema.db.source(), model);
mongodb::add_at_map_for_id(&mut actions, &params, validated_schema.db.source_assert_single(), model);

mongodb::add_native_for_auto_id(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
model,
datasource.unwrap(),
);
Expand All @@ -71,7 +82,7 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec
multi_schema::add_schema_block_attribute_enum(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
config,
enumerator,
)
Expand All @@ -88,15 +99,15 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec
relations::add_referenced_side_unique(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
complete_relation,
);

if relation.is_one_to_one() {
relations::add_referencing_side_unique(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
complete_relation,
);
}
Expand All @@ -105,7 +116,7 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec
relations::add_index_for_relation_fields(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
complete_relation.referencing_field(),
);
}
Expand All @@ -114,7 +125,7 @@ pub(crate) fn available_actions(schema: String, params: CodeActionParams) -> Vec
relation_mode::replace_set_default_mysql(
&mut actions,
&params,
validated_schema.db.source(),
validated_schema.db.source_assert_single(),
complete_relation,
config,
)
Expand Down
5 changes: 2 additions & 3 deletions prisma-fmt/src/code_actions/multi_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ pub(super) fn add_schema_to_schemas(
formatted_attribute,
true,
// todo: update spans so that we can just append to the end of the _inside_ of the array. Instead of needing to re-append the `]` or taking the span end -1
Span::new(span.start, span.end - 1),
Span::new(span.start, span.end - 1, psl::parser_database::FileId::ZERO),
params,
)
}
None => {
let has_properties = datasource.provider_defined()
|| datasource.url_defined()
let has_properties = datasource.provider_defined() | datasource.url_defined()
|| datasource.direct_url_defined()
|| datasource.shadow_url_defined()
|| datasource.relation_mode_defined()
Expand Down
49 changes: 29 additions & 20 deletions prisma-fmt/src/get_config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use psl::Diagnostics;
use psl::{Diagnostics, ValidatedSchema};
use serde::Deserialize;
use serde_json::json;
use std::collections::HashMap;

use crate::validate::SCHEMA_PARSER_ERROR_CODE;
use crate::{schema_file_input::SchemaFileInput, validate::SCHEMA_PARSER_ERROR_CODE};

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct GetConfigParams {
prisma_schema: String,
prisma_schema: SchemaFileInput,
#[serde(default)]
ignore_env_var_errors: bool,
#[serde(default)]
Expand Down Expand Up @@ -43,29 +43,38 @@ pub(crate) fn get_config(params: &str) -> Result<String, String> {
}

fn get_config_impl(params: GetConfigParams) -> Result<serde_json::Value, GetConfigError> {
let wrap_get_config_err = |errors: Diagnostics| -> GetConfigError {
use std::fmt::Write as _;

let mut full_error = errors.to_pretty_string("schema.prisma", &params.prisma_schema);
write!(full_error, "\nValidation Error Count: {}", errors.errors().len()).unwrap();

GetConfigError {
// this mirrors user_facing_errors::common::SchemaParserError
error_code: Some(SCHEMA_PARSER_ERROR_CODE),
message: full_error,
}
};

let mut config = psl::parse_configuration(&params.prisma_schema).map_err(wrap_get_config_err)?;
let mut schema = psl::validate_multi_file(params.prisma_schema.into());
if schema.diagnostics.has_errors() {
return Err(create_get_config_error(&schema, &schema.diagnostics));
}

if !params.ignore_env_var_errors {
let overrides: Vec<(_, _)> = params.datasource_overrides.into_iter().collect();
config
schema
.configuration
.resolve_datasource_urls_prisma_fmt(&overrides, |key| params.env.get(key).map(String::from))
.map_err(wrap_get_config_err)?;
.map_err(|diagnostics| create_get_config_error(&schema, &diagnostics))?;
}

Ok(psl::get_config(&config))
Ok(psl::get_config(&schema.configuration))
}

fn create_get_config_error(schema: &ValidatedSchema, diagnostics: &Diagnostics) -> GetConfigError {
use std::fmt::Write as _;

let mut rendered_diagnostics = schema.render_diagnostics(diagnostics);
write!(
rendered_diagnostics,
"\nValidation Error Count: {}",
diagnostics.errors().len()
)
.unwrap();

GetConfigError {
// this mirrors user_facing_errors::common::SchemaParserError
error_code: Some(SCHEMA_PARSER_ERROR_CODE),
message: rendered_diagnostics,
}
}

#[cfg(test)]
Expand Down
47 changes: 44 additions & 3 deletions prisma-fmt/src/get_dmmf.rs

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion prisma-fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ mod code_actions;
mod get_config;
mod get_dmmf;
mod lint;
mod merge_schemas;
mod native;
mod preview;
mod schema_file_input;
mod text_document_completion;
mod validate;

Expand Down Expand Up @@ -89,6 +91,14 @@ pub fn validate(validate_params: String) -> Result<(), String> {
validate::validate(&validate_params)
}

/// Given a list of Prisma schema files (and their locations), returns the merged schema.
/// This is useful for `@prisma/client` generation, where the client needs a single - potentially large - schema,
/// while still allowing the user to split their schema copies into multiple files.
/// Internally, it uses `[validate]`.
pub fn merge_schemas(params: String) -> Result<String, String> {
merge_schemas::merge_schemas(&params)
}

pub fn native_types(schema: String) -> String {
native::run(&schema)
}
Expand Down Expand Up @@ -225,7 +235,7 @@ pub(crate) fn range_to_span(range: Range, document: &str) -> ast::Span {
let start = position_to_offset(&range.start, document).unwrap();
let end = position_to_offset(&range.end, document).unwrap();

ast::Span::new(start, end)
ast::Span::new(start, end, psl::parser_database::FileId::ZERO)
}

/// Gives the LSP position right after the given span.
Expand Down
Loading

0 comments on commit 81129cf

Please sign in to comment.