-
-
Notifications
You must be signed in to change notification settings - Fork 113
merge dev to main (v2.15.0) #2126
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
Conversation
Warning Rate limit exceeded@ymc9 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 34 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis set of changes introduces a new Elysia adapter for server integration, adds extensive tests for the adapter, and enhances model metadata and delegate logic to support relation actions ( Changes
Sequence Diagram(s)Elysia Adapter Request HandlingsequenceDiagram
participant Client
participant ElysiaApp
participant ElysiaHandler
participant PrismaClient
participant RPCApiHandler
Client->>ElysiaApp: HTTP Request
ElysiaApp->>ElysiaHandler: Route Handler Invocation
ElysiaHandler->>PrismaClient: getPrisma(context)
ElysiaHandler->>RPCApiHandler: Handle(method, path, query, body, prisma, meta, schemas, logger)
RPCApiHandler-->>ElysiaHandler: { status, body }
ElysiaHandler-->>ElysiaApp: Response
ElysiaApp-->>Client: HTTP Response
Delegate Cascade Delete FlowsequenceDiagram
participant Client
participant DelegateProxyHandler
participant CrudContract
Client->>DelegateProxyHandler: delete(model, args)
DelegateProxyHandler->>CrudContract: Query related entities for cascade delete
loop For each related entity with Cascade
DelegateProxyHandler->>DelegateProxyHandler: doDelete(related model, related args)
end
DelegateProxyHandler->>CrudContract: Delete main entity
DelegateProxyHandler-->>Client: Deleted entity hierarchy
Metadata Generation with Relation ActionssequenceDiagram
participant ModelMetaGenerator
participant DataModelField
ModelMetaGenerator->>DataModelField: Inspect @relation attributes
ModelMetaGenerator->>ModelMetaGenerator: getOnDeleteAction(field)
ModelMetaGenerator->>ModelMetaGenerator: getOnUpdateAction(field)
ModelMetaGenerator-->>ModelMetaGenerator: Write onDeleteAction/onUpdateAction to metadata
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (10)
tests/regression/tests/issue-2117.test.ts (1)
21-24
: Computed field doesn’t actually use the declared dependency
needs: { username: true }
declares thatpageUrl
depends onusername
, yet thecompute
callback always returns the constant string"foo"
and ignores theusername
argument. At best this is confusing, at worst future maintainers might rely onusername
being fetched unnecessarily.If the URL is always the same, drop the
needs
declaration; otherwise build the URL fromusername
.- needs: { username: true }, - compute: () => `foo`, + // needs omitted – constant string, no real dependency + compute: () => 'foo',(or compute on
username
if that was the intent).tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts (4)
479-490
: Flaky assertion onupdatedAt
– allow equality
updatedAt
is stored with millisecond (or even-microsecond) precision depending on the backing database.
Two consecutive writes executed in the same tick can produce identical timestamps, which will make the strict
>
assertion intermittently fail on fast machines or CI.-expect(updated.updatedAt.getTime()).toBeGreaterThan(read.updatedAt.getTime()); +expect(updated.updatedAt.getTime()).toBeGreaterThanOrEqual(read.updatedAt.getTime());The same reasoning applies to any other
updatedAt
comparison below.
618-631
: Same potential flakiness forupdatedAt
comparisonReplicate the
>=
change here to avoid nondeterministic failures.
1031-1049
: Same potential flakiness forupdatedAt
in the upsert flowApply the
>=
change here as well.
1109-1156
:delete cascade
test: add explicit count assertions for stronger signalThe current checks rely on
findUnique
returningnull
. Adding explicit row-count assertions makes the intent clearer and gives more precise diagnostics should the cascade break.await expect(db.item.findUnique({ where: { id: 2 } })).toResolveNull(); +await expect(db.item.count()).resolves.toBe(0); ... await expect(db.itemContent.findUnique({ where: { id: 3 } })).toResolveNull(); +await expect(db.itemContent.count()).resolves.toBe(0);(optional but useful)
packages/server/src/elysia/handler.ts (3)
40-43
: Repeated query-string keys are silently discarded
Object.fromEntries(url.searchParams)
turns a multi-map (URLSearchParams) into a plain object, meaning only the last value of duplicate keys is kept.
If the API needs to support filters like?id=1&id=2
, this implementation will drop values.-const query = Object.fromEntries(url.searchParams); +const query: Record<string, string | string[]> = {}; +url.searchParams.forEach((v, k) => { + if (k in query) { + query[k] = Array.isArray(query[k]) ? [...(query[k] as string[]), v] : [query[k] as string, v]; + } else { + query[k] = v; + } +});
58-76
: Swallowed error hinders troubleshootingThe catch-all replaces the original error with a generic message. Down-stream callers (including tests) cannot see stack traces, and production logs get no clues.
Consider at least logging the error or re-throwing it in non-production environments:
} catch (err) { - set.status = 500; - return { message: 'An internal server error occurred' }; + options.logger?.error?.('elysia-handler', err); + set.status = 500; + return { message: 'An internal server error occurred' }; }
30-38
: 500 may not be the best signal for missing Prisma clientIf
getPrisma
returnsundefined
, it looks like a configuration issue rather than a server crash. Returning 503 (Service Unavailable) or 500 with a more specific hint would better reflect reality and improve observability.packages/runtime/src/enhancements/node/delegate.ts (2)
1206-1237
: Potential N+1 queries during cascade deleteFor every relation field flagged
Cascade
, you run an extrafindMany
even if no matching rows exist.
On large deletes this can explode to N×M round-trips.Consider batching the queries or pre-selecting all relations with a single
include
instead of per-field queries.
820-832
: Duplicate logic forsimpleUpdateMany
flagThe same check (base fields +
@updatedAt
inheritance) exists in two places (updateMany
and visitor’supdateMany
). Extracting it into a private helper will prevent future divergence.private isSimpleUpdateMany(model: string, data: any, where?: any): boolean { /* … */ }Also applies to: 958-963
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (23)
package.json
is excluded by!**/*.json
packages/ide/jetbrains/package.json
is excluded by!**/*.json
packages/language/package.json
is excluded by!**/*.json
packages/misc/redwood/package.json
is excluded by!**/*.json
packages/plugins/openapi/package.json
is excluded by!**/*.json
packages/plugins/swr/package.json
is excluded by!**/*.json
packages/plugins/tanstack-query/package.json
is excluded by!**/*.json
packages/plugins/trpc/package.json
is excluded by!**/*.json
packages/plugins/trpc/tests/projects/nuxt-trpc-v10/package-lock.json
is excluded by!**/package-lock.json
,!**/*.json
packages/plugins/trpc/tests/projects/nuxt-trpc-v10/package.json
is excluded by!**/*.json
packages/plugins/trpc/tests/projects/nuxt-trpc-v11/package-lock.json
is excluded by!**/package-lock.json
,!**/*.json
packages/plugins/trpc/tests/projects/nuxt-trpc-v11/package.json
is excluded by!**/*.json
packages/plugins/trpc/tests/projects/t3-trpc-v11/package-lock.json
is excluded by!**/package-lock.json
,!**/*.json
packages/plugins/trpc/tests/projects/t3-trpc-v11/package.json
is excluded by!**/*.json
packages/runtime/package.json
is excluded by!**/*.json
packages/schema/package.json
is excluded by!**/*.json
packages/sdk/package.json
is excluded by!**/*.json
packages/server/package.json
is excluded by!**/*.json
packages/testtools/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
,!**/*.yaml
tests/integration/test-run/package.json
is excluded by!**/*.json
tests/integration/tests/frameworks/nextjs/test-project/package.json
is excluded by!**/*.json
tests/integration/tests/frameworks/trpc/test-project/package.json
is excluded by!**/*.json
📒 Files selected for processing (16)
packages/ide/jetbrains/build.gradle.kts
(1 hunks)packages/runtime/src/cross/model-meta.ts
(2 hunks)packages/runtime/src/enhancements/node/delegate.ts
(6 hunks)packages/runtime/src/enhancements/node/policy/policy-utils.ts
(1 hunks)packages/runtime/src/enhancements/node/utils.ts
(1 hunks)packages/sdk/src/model-meta-generator.ts
(2 hunks)packages/server/src/elysia/handler.ts
(1 hunks)packages/server/src/elysia/index.ts
(1 hunks)packages/server/tests/adapter/elysia.test.ts
(1 hunks)script/test-scaffold.ts
(1 hunks)tests/integration/tests/cli/plugins.test.ts
(2 hunks)tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts
(6 hunks)tests/integration/tests/enhancements/with-delegate/plugin-interaction.test.ts
(4 hunks)tests/integration/tests/enhancements/with-delegate/utils.ts
(1 hunks)tests/regression/tests/issue-2106.test.ts
(1 hunks)tests/regression/tests/issue-2117.test.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
script/test-scaffold.ts (1)
packages/testtools/src/schema.ts (1)
run
(45-57)
packages/sdk/src/model-meta-generator.ts (1)
packages/sdk/src/utils.ts (3)
getAttribute
(141-157)getAttributeArg
(172-182)isEnumFieldReference
(196-198)
tests/regression/tests/issue-2117.test.ts (1)
packages/testtools/src/schema.ts (1)
loadSchema
(163-369)
tests/regression/tests/issue-2106.test.ts (1)
packages/testtools/src/schema.ts (1)
loadSchema
(163-369)
packages/server/src/elysia/handler.ts (3)
packages/server/src/types.ts (1)
AdapterBaseOptions
(32-56)packages/server/src/shared.ts (1)
loadAssets
(5-21)packages/runtime/src/types.ts (1)
DbClientContract
(91-93)
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
packages/runtime/src/cross/model-meta.ts (1)
resolveField
(213-221)
packages/server/tests/adapter/elysia.test.ts (3)
packages/testtools/src/schema.ts (1)
loadSchema
(163-369)packages/server/tests/utils.ts (1)
schema
(3-29)packages/server/src/elysia/handler.ts (1)
createElysiaHandler
(25-82)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: OSSAR-Scan
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
🔇 Additional comments (17)
script/test-scaffold.ts (1)
22-22
: Align Prisma and client package versions
Thenpm i
invocation now installsprisma@6.8.x
and@prisma/client@6.8.x
instead of6.7.x
, keeping the scaffolded project in sync with the updated integration tests and ensuring consistent Prisma versions across your testing setup.tests/integration/tests/cli/plugins.test.ts (2)
78-78
: Update runtime Prisma client version indepPkgs
Bumped@prisma/client
from6.7.x
to6.8.x
in the runtime dependencies array (depPkgs
), matching the scaffold script change and avoiding version drift during test execution.
88-88
: Update Prisma CLI version indevDepPkgs
Bumpedprisma
from6.7.x
to6.8.x
in the development dependencies array (devDepPkgs
), maintaining alignment with the runtime package and the scaffold setup.packages/ide/jetbrains/build.gradle.kts (1)
12-12
: Version bump for release v2.15.0This version update aligns with the PR objective to merge dev into main for release v2.15.0.
packages/server/src/elysia/index.ts (1)
1-1
: Clean module export patternThis barrel file provides a clean public API for the new Elysia adapter, making imports simpler for consumers.
tests/integration/tests/enhancements/with-delegate/utils.ts (1)
15-15
: AddedupdatedAt
field to Asset modelAdding the
@updatedAt
field to the baseAsset
model will ensure automatic timestamp updates on modifications, which is essential for testing the enhanced delegate update logic.tests/integration/tests/enhancements/with-delegate/plugin-interaction.test.ts (4)
68-69
: Updated test data withupdatedAt
fieldAdded
updatedAt
field to the test object to match the updated schema. This maintains consistency with the changes in theAsset
model.
78-79
: Updated test data withupdatedAt
fieldAdded
updatedAt
field to the test object to match the updated schema. This maintains consistency with the changes in theAsset
model.
92-93
: Updated test data withupdatedAt
fieldAdded
updatedAt
field to the test object to match the updated schema. This maintains consistency with the changes in theAsset
model.
104-105
: Updated test data withupdatedAt
fieldAdded
updatedAt
field to the test object to match the updated schema. This maintains consistency with the changes in theAsset
model.packages/runtime/src/enhancements/node/utils.ts (1)
10-10
: Improved BigInt handling during serialization.The change ensures consistent serialization of
bigint
values by always converting them to strings. This prevents "TypeError: Do not know how to serialize a BigInt" errors that can occur with standard JSON serialization.packages/runtime/src/cross/model-meta.ts (2)
23-26
: Good addition: RelationAction type for referential integrity.The new
RelationAction
type clearly defines the possible referential actions for relations, which will be used to control behavior when related records are deleted or updated.
82-91
: Solid extension of the FieldInfo type for relation actions.These new properties allow for capturing the
onDelete
andonUpdate
referential actions from the schema's relation fields. This is particularly important for implementing cascade delete functionality.packages/sdk/src/model-meta-generator.ts (2)
314-325
: Good implementation of relation action metadata generation.The code correctly extracts and writes the
onDeleteAction
andonUpdateAction
properties to the field metadata. This enables the runtime to properly handle relation behaviors like cascade deletes.
584-604
: Well-structured helper functions for relation actions.The
getOnDeleteAction
andgetOnUpdateAction
functions follow a consistent pattern for extracting relation action information from the model's attributes. They correctly handle the extraction of enum field references from the relation attribute.tests/regression/tests/issue-2106.test.ts (1)
1-19
: Good regression test for BigInt handling.This test verifies that the system correctly handles BigInt fields during record creation, which validates the serialization improvements in
formatObject
. The test is concise and focuses on the specific issue it's designed to catch.packages/runtime/src/enhancements/node/delegate.ts (1)
1163-1183
: Unbounded recursive cascade delete – verify for cyclic relations
doDelete
recursively calls itself for cascade relations without keeping a visited-set.
Mutually-referencing models withonDelete: Cascade
could cause infinite recursion.Please verify with a cyclic schema; if reproducible, guard with a
Set<string>
of(model,id)
pairs.
No description provided.