Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from prisma:main #122

Open
wants to merge 601 commits into
base: main
Choose a base branch
from
Open

[pull] main from prisma:main #122

wants to merge 601 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Jun 12, 2023

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

renovate bot and others added 28 commits December 15, 2023 10:54
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Planetscale driver

Re: prisma/prisma#22404

* Delete pnpm-lock.yaml file
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
* Move `itertools` to workspace dependencies to make it easier to manage
  its version.

* Update `itertools` to 0.12.

* Update `sqlformat` to 0.2.3 to avoid having both
  `itertools 0.10.5` and `itertools 0.12.0` in the compiled binaries.

Closes: prisma/team-orm#750
…ne-node-api` and `query-engine-wasm` (#4521)

* feat(quaint): allow wasm32-unknown-unknown compilation; currently fails on native

* feat(quaint): split postgres connector into native and wasm submodules

* feat(quaint): split mysql connector into native and wasm submodules

* feat(quaint): recover wasm error for mysql

* feat(quaint): split mssql connector into native and wasm submodules

* feat(quaint): split sqlite connector into native and wasm submodules

* chore(quaint): fix clippy when compiling natively

* chore(quaint): fix clippy when compiling to wasm32-unknown-unknown

* chore(quaint): update README

* chore(quaint): rename "*-connector" feature flag to "*-native"

* feat(quaint): enable pure Wasm SqliteError

* feat(query-connect): allow wasm32-unknown-unknown compilation

* feat(sql-query-connector): allow wasm32-unknown-unknown compilation

* chore(query-engine-wasm): add currently unused local crates to test wasm32-unknown-unknown compilation

* chore: update Cargo.lock

* chore: remove leftover comments

* feat(query-core): allow wasm32-unknown-unknown compilation

* chore(sql-query-connector): fix clipppy on wasm32

* chore: remove leftover comment

* chore: remove leftover comment

* feat(driver-adapters): enable Wasm on request-handlers

* WIP: refactor mysql module to flatten its structure

* feat(quaint): flatten mssql connector module

* feat(quaint): flatten postgres connector module

* feat(quaint): flatten sqlite connector module

* chore(quaint): export all public definitions in connector "url" modules

* chore(quaint): refactor tests for connectors, addressing feedback

* chore: add comment on MysqlAsyncError

* chore: add comment on ffi.rs for sqlite

* chore: replace awkward "super::super::" with "crate::..."

* chore: add comments around "query_core::executor::task"

* chore: add comments around "query_core::executor::task"

* chore: add "request-handlers" to "query-engine-wasm"

* chore: add wasm dependencies to Cargo workspace

* feat(driver-adapters): move napi-specific code into "napi" module, prepare empty "wasm" module

* feat(driver-adapters): extracted platform-agnostic "DriverAdapterError" into "driver_adapters::error"

* chore(driver-adapters): add "driver-adapters" to "query-engine-wasm"

* feat(driver-adapters): add Wasm-specific "async_js_function"

* feat(driver-adapters): extracted common types to "driver_adapters::types"

* feat(driver-adapters): extracted "TryFrom<JSResultSet> for QuaintResultSet" to "driver_adapters::conversion::js_to_quaint"

* feat(driver-adapters): allow feature-complete Wasm compilation of "driver-adapters"

* feat(driver-adapters): plug "driver-adapters" to "query-engine-wasm"

* chore: remove .cargo, add it to .gitignore

* chore: move "task" module into its own file

* fix(driver-adapters): ci for "request-handlers"

* fix(driver-adapters): ci for "request-handlers"

* fix(driver-adapters): clippy compile error on "query-engine-wasm"

* chore(driver-adapters): fix conflicting library name warning on "cargo build"

* chore: fix conflicts

* chore: fixed some clippy warnings

* chore: add .cargo to .gitignore

* feat(query-engine-wasm): ported some logic from query-engine-node-api in a wasm32-compatible fashion

* Add connect/disconnect

* fix: remove tokio-induced panic in "connect"

* feat: remove ducktor

* feat(driver-adapters): remove "queryable" into its own module

* Couple of fixes

1. Build schema and connect sequentually
2. Print full stacktrace for WASM error
3. Expand example to attempt a query

* Fix `Instant::now` usage

Replace `Instant::now` with a custom library, that will use appriate
time/date functions for the platforms. For native, it is `std::time`,
for WASM in should probably be `performance::now()` but it is a no-op
stub for now.

* fix(driver-adapters): understand "flavour" and adjust casing in "JSResultSet"

* feat(driver-adapters): add some Into traits for "JsResult"

* Fix JSResult parsing

* Reorganize example

Switch to sqlite so cloud services are not required
Save schema to external file

* Fix some of the warnings

* Remove unused file

* Fix WASM transaction binding

Correctly gets to a point of starting the tranasction and executing the
query, fails on parsing the results like normal queries do.

* Cleanup

* feat(driver-adapters): fix enum parsing, add "wasm-rs-dbg" crate for dev development

* chore(driver-adapters): remove unused "src/wasm/queryable.rs"

* chore(driver-adapters): add "createOne" and "driverAdapters" preview feature to example

* chore(driver-adapters): add wasm-bindgen-test example

* chore(driver-adapters): update Cargo.lock

* Handle non-promise return values

* Run tests on WASM

* feat(core): allow Drop'ing futures running in loop in wasm32-* via controlled spawns

* feat(chore): add Arc<DriverAdapter> comment

* feat(chore): re-enable previous "disconnect()"

* feat(chore): update example.js

* fix(query-engine-node-api): fix compilation errors

* Update cuid

* Remove one more isntant usage

* chore(driver-adapters): simplify async_js_function API

* chore(driver-adapters): unify napi/wasm errors into "crate::JsResult"

* chore(driver-adapters): continue unifying napi/wasm functions

* chore(driver-adapters): unify napi/wasm logic for proxy

* chore(driver-adapters): unify napi/wasm logic queryable.rs and proxy.rs

* chore(driver-adapters): unify napi/wasm logic for transaction.rs

* chore(driver-adapters): clippy fixes

* chore(driver-adapters): cli
ppy fixes

* chore: remove dbg! output

* chore: remove dbg! output

* Fix itx panic

* Remove unused import

* Fix hanging itx

* fix insta tests

Strictly speaking, not related to wasm engine at all - we bumped `insta`
at some point and that required adding `allow_duplicates` macro around
the loop.

Close prisma/team-orm#651

* feat(query-engine-wasm): enable tracing and bits of telemetry

* chore: clippy

* Fix panic kills running engine in query-engine-tests (#4499)

* I didn't have wasm-pack installed, let's fix that

* Update wasm-bindgen-futures to 0.4.39

This includes rustwasm/wasm-bindgen#3203 that use queueMicrotask
to transalate spawn_local rust code.

This has fixed rustwasm/wasm-bindgen#2392 which was an issue about not being able to catch async wasm traps. This might (or not) have an effect on the issue we are trying to solve in here.

* Revert "Update wasm-bindgen-futures to 0.4.39"

This reverts commit 9a494dc.

* Restart executor when it dies

* Document Restartable

* Remove async_panic_to_js_error in WASM query engine

* Rename p -> process

* Use tokio::sync::RwLock rather than futures::lock::Mutex

* Better error messaging

* Fixing clippy

* Exclude unit tests for wasm32 when compiling the binary for other architectures

* Fix duplicate snapshots in json_filters test

* Size low hanging fruits

Removes following functionality from WASM engine:
- GraphQL protocol
- DMMF
- SDL Schema

Neither of the features are used by the client runtimes and thrid party
clients don't and can not use WASM engine, so it is safe to remove.

* feat(driver-adapters): serialize empty values as "null" rather than "undefined"

* chore: fixed query-engine-node-api build

* chore: bumped wasm-bindgen version to 0.2.89

* chore: clean up quaint transitive dependencies

* chore: removed wasm.rs test

* chore: removed temporary wasm machinery

* chore: fix clippy

* chore: remove unwrap from "sleep"

* chore: revert unnecessary psl change

* chore(driver-adapters): fix unit tests

* chore(driver-adapters): add clippy check for wasm32

* chore(driver-adapters): add clippy check for wasm32

* chore: fix clippy

* Revert "chore: removed wasm.rs test"

This reverts commit 60b0d8c.

* test(driver-adapters): add byte tests for conversion

* Revert "Revert "chore: removed wasm.rs test""

This reverts commit 481ba65.

* [skip ci] chore: fix build CI check logic

* Revert "[skip ci] chore: fix build CI check logic"

This reverts commit 28c6ff9.

* Stop using removed method

* Fix broken JS

* chore(review): rename threadsafe_fn to fn_

* chore(review): add comment related to js_sys::Reflect in JsObjectExtern

* chore(review): rename SendFuture to UnsafeFuture, improving comments

* chore(review): use fully-specialized types for wasm/napi-specific logic, when possible; apply clippy fixes

* chore(review): rename JsResult into AdapterResult, reduce duplication, improve comments

* chore(review): remove redudant full type qualifier

* chore(review): revert changes to psl-core

* chore(review): improve comments on js.rs

* Test fixes for NAPI tests (#4515)

* chore(review): comment on spawn_controlled actors, add error tracing to unexpected case

* chore(review): remove unused dependency

* chore(review): move wasm/napi-specific task JoinHandle stuff to crosstarget-utils

* feat(query-engine-common): reduce duplicated code between "query-engine-wasm" and "query-engine-node-api"

* qe-wasm: Partially fix tests (#4517)

* qe-wasm: Partially fix the test suite

1. Bash script for build did not abort on error, hence sed error on
   linux went unnoticed.
2. We don't actually need sed trickery sincce `wasm-pack` has a flag for
   changing binary name.
3. `tracing` feature does not actually work on WASM even partially: it panics on
   `Instant` invokation as soon as first span is created. Since we are
   running tests with all preview features enabled, that means that
   practically any test panics now. Disabled it again.

A lot of tests are still failing on ThreadRng invocation and stacktrace
is not really helpful, but I still think it's better if we get it
working.

* Update query-engine/query-engine-wasm/build.sh

* qe-wasm: Fix RNG on Node 18 in a test runner (#4526)

* feat(query-engine-common): move more stuff to "query-engine-common"

* feat: limit the number of conditional flags for each native-only struct field by introducing *Native structs conditionally

* feat: remove unused code (supersedes #4524)

---------

Co-authored-by: Miguel Fernandez <miguel@mff.io>
Co-authored-by: Sergey Tatarintsev <tatarintsev@prisma.io>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Miguel Fernández <fernandez@prisma.io>
* feat(query-engine-wasm): move wasm-opt options from Cargo.toml to build.sh, to share subset of it between multiple build profiles

* feat(query-engine-wasm): add wasm-inspect.sh to analyse human-friendly WebAssembly code (*.wat)

* chore: fix shellcheck SC2155

* feat(query-engine-wasm): default to "dev" profile; one can still opt in for WASM_BUILD_PROFILE="profiling"

* feat(query-engine-wasm): update README.md
* Build wasm query engine within nix environement

Ensures that all necessary tooling is always available for when it is
built. Affected jobs:

- Adapter tests
- Size comparison job
- WASM engine release

Fix prisma/team-orm#752

* feat(query-engine-wasm) [size]: manually specify connector registry (#4586)

* Update nix/all-engines.nix

Co-authored-by: Alexey Orlenko <alex@aqrln.net>

---------

Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
The present PR adds continuous benchmarking of the current query-engine WASM, comparing it with:
- NAPI on the same branch
- WASM in main
- WASM baseline (at the beginning of our performance inquiries)

It provides a comment [like this](#4567 (comment)) with the benchmark results for different queries in text mode. 

Benchmarks are considered to have regressed if there is more than one benchmark 1% slower in the current WASM query engine compared to the `latest` version (coming from main)
…4592)

Fixes the following warning:

```
direnv: `nix_direnv_watch_file` is deprecated - use `watch_file`
```
* psl: Ensure `set_config_dir` can be eliminated if not used

Due to dynamic dispatch, optimizer does not remove it from WASM bundle,
even though it is not used. It brings in heavy URL parser that adds
around 270K uncompressed/130K gzip. This PR rewrites it to be a free
function outside of `Connector` trait that does not have this problem.

Fix prisma/team-orm#772

* Hello clippy my old friend
Make it possible to conjure a local debug build of
`@prisma/prisma-schema-wasm` npm package with `nix build
.#prisma-schema-wasm.dev` command.

Normal `nix build .#prisma-schema-wasm` still builds in release profile
by default.

This makes it easier to test local changes to DMMF end-to-end with
TypeScript client generator.
* qe: Remove global JS connector variable

It is now passed as parameter for `ConnectorKind::Js`.
Was initial done as size exploration work that have not quite worked
out. I still find the refactor on itself valuable though.

* Fix test setup compilation
Not so much savings in terms of raw size, mostly just cleaning up visual
noise.
Usage: `node visualiz-twiggy.mjs`
Produces result.html file with output of `twiggy dominators` with the
collabsible sections.
* qe: Remove Query::clone

Extra 14KB to the WASM bundle

* Fix quaint tests
* Ignore WAT files

* Fix wasm-benchmarks

* Prevent noise, raise percentage by 1%
* feat(query-engine-wasm): remove redundant validations

* feat(query-engine-wasm): remove useless tracing

* feat(query-engine-wasm): remove useless variables and mutables

* feat(query-engine-wasm): fix engine protocol JSON

* feat(query-engine-wasm): remove .unwrap() in favor of default log level

* feat(query-engine-wasm): remove telemetry stuff in logger

* feat(query-engine-wasm): remove useless Arc::clone
* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Added quickfix for mongodb native type with `@default(auto)`

closes prisma/language-tools#1548
Implement per-query configuration of relation load strategy as described in https://www.notion.so/prismaio/Relation-load-strategy-API-013e3ba957a34d45b4de1b722ca6804d, particularly [this section](https://www.notion.so/prismaio/Relation-load-strategy-API-013e3ba957a34d45b4de1b722ca6804d?pvs=4#045efb0e3cd54caeb6584d65f667fbb5) (Variant 1, only top level).

This allows to choose the relation load strategy for all relations in a single query.

Engine API:

```graphql
query {
  findManyUser(relationLoadStrategy: join) {
    login
    posts { title }
  }
}
```

Client API:

```ts
await prisma.user.findMany({
  relationLoadStrategy: 'join', // or 'query'
  select: {
    login: true,
    posts: {
      title: true,
    },
  },
})
```

The new `relationLoadStrategy` argument is available in the following operations:

- findMany
- findFirst
- findFirstOrThrow
- findUnique
- findUniqueOrThrow
- create
- update
- delete
- upsert

The argument is not available in the following operations:
- aggregate
- groupBy
- createMany
- updateMany
- deleteMany

Tests are included for all operations in this PR.

Additionally, it must not be available in the `count` operation, which needs to be handled separately on the client side, because `count` is a synthetic operation that does not exist in the query schema and is not known to the engine, and its TS types are generated based on `findMany` args rather than `aggregate` that it translates to.

Next steps:
- Finalize the Client integration PR
- Implement the global setting

Part of prisma/team-orm#703
Closes: prisma/team-orm#801
Client PR: prisma/prisma#22483
`nodejs` package installs node 21 after update, which can't build driver
adapters locally.
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
jkomyno and others added 30 commits May 30, 2024 16:21
* prisma-fmt: Make `parse_confgiration_multi` error tolerant

Now the function never fails and always returns both `Config` and
`Diagnostics`. In case of errors, `Diagnostic` would be non-empty, but
it will still try to return as much of a config as it was able to parse.

This is useful mostly for dev tools - they need to be able to read
preview feature from more invalid files than old `get_config` would've
allowed. It also improves diagnostics in the CLI since we are now also
able to tell that user wanted to have more cases.

This is a breaking change to consumers of `prisma-fmt`: both prisma cli
and language-tools would need to be adapted to the new signature.

Contributes to prisma/team-orm#1143
Contributes to prisma/team-orm#1127 (opportunistic refactor)

* Rename method once more
* Something broke in the definition for these quickfixes in language-tools so this is an opportunistic to both fix and move them to engines.

Reference: https://github.com/prisma/language-tools/blob/53e70077abbcf26c03c8aabb416521dba248804b/packages/language-server/src/lib/code-actions/index.ts#L137-L166

* Also added block qfs for composite types
- enum
- type
* Fix drift when FKs have same columns
* Updated FK filtering to use hashset of seen fks

fixes prisma/prisma#23043
related #1904
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* fix(d1): allow custom max_bind_values

* feat(driver-adapters-executor): allow reading "maxBindValues" from Driver Adapter

* feat(connector-test-kit-rs): "ExternalInitializer::init*" methods now return "InitResult"

* feat(connector-test-kit-rs): update "Runner::load" after "ExternalInitializer::init*" changes; add optional "override_local_max_bind_values" argument

* chore(connector-test-kit-rs): set optional "override_local_max_bind_values" argument to None when manually invoking "Runner::load()"

* chore(connector-test-kit-rs): remove "driver_adapter_max_bind_value" from D1

* fix(connector-test-kit-rs): restore "ConnectorVersion::is_wasm", add D1 to it

* DRIVER_ADAPTERS_BRANCH=integration/fix-sqlite-d1-max-bind-values chore: retrigger CI/CD

* DRIVER_ADAPTERS_BRANCH=integration/fix-sqlite-d1-max-bind-values chore: uncomment D1 test

* DRIVER_ADAPTERS_BRANCH=integration/fix-sqlite-d1-max-bind-values chore: retrigger CI/CD

* DRIVER_ADAPTERS_BRANCH=integration/fix-sqlite-d1-max-bind-values chore: retrigger CI/CD

---------

Co-authored-by: Flavian Desverne <flavian.dsv@gmail.com>
…4898)

* prisma-fmt: Accept multiple files as an input for native types hints

Autocomplete for native types is broken at the moment if schema folder
is used.

* Remove dbg!

* Clippy, rustfmt
* psl: Make `prismaSchemaFolder` feature public

* Fix tests

* Update snapshots
* test(query-engine-wasm): add tests for prisma/prisma#23743 and prisma/prisma#23919

* chore: fix clippy

* chore: adjust tests, exclude failing test on D1
* test(query-engine): Fix PlanetScale test, #4482

* test(query-engine): Fix PlanetScale test, #4485
* Add newline parsing for composite types and enums

* Add test for crlf endings

* separate newline helper
…rroring what we expect in PG and CRDB. (#4917)

This means that errors will now surface the socket connection to users when encountering, for example, connectivity issues.

This was already happening by default for PG and CRDB as they expect sockets through the `host` query-arg, however our default host parsing was not picking this up for MySQL as it was expected through `socket` there instead.

Related PR: prisma/prisma#24222
* Uses wasm-logger feature
update script for usage w/ language-tools now uses said feature
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* feat(user-facing-errors): add missing branch for SQLite

* feat(quaint): use explicit connection flags for SQLite

* feat(quaint): use BEGIN IMMEDIATE to avoid busy errors on concurrent SQLite writes

* test(connector-test-kit-rs): add Rust regression test for prisma/prisma#11789

* chore(quaint): adjust sqlite comment

* chore(user-facing-errors): simplify busy error message for SQLite
…t contains multi-byte characters (#4815)

Updated offsets to be UTF-16. This means that our spans will no-longer de-sync with the schema when we run into schemas containing multibyte characters

---------

Co-authored-by: Alexey Orlenko <alex@aqrln.net>
* fix(query-engine): uncomment D1 "createMany" tests

* chore: uncomment missing test
Needed for prisma/team-orm#1210

Co-authored-by: Sophie Atkins <atkins@prisma.io>
* feat(prisma-fmt): Add source file path to datasource block too

Contribute to prisma/team-orm#1210

* Fix tests

* Fix tests

* Clippy, why are you like this
* fix(query-engine): fix D1 tracing bug on comments

* fix(quaint): fix test expectations on SQLite
add documentation helper to Top
add name helper to FieldType
Added more positions:
  ModelPosition::Name
  FieldPosition::{Name,Type}
  SourcePosition::Name
  GeneratorPosition
  CompositeTypePosition
split out find_at_position
added find_at_position doc

Added topwalker
some clean-up of publicity
added indexing for generatorid on schema ast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet