-
-
Couldn't load subscription status.
- Fork 126
refactor(runtime): separate node and edge enhancement code for edge-runtime compatibility #1684
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
WalkthroughWalkthroughThe changes involve the addition of new files and modifications to existing files within the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant EnhancerGenerator
participant PolicyGenerator
participant PermissionCheck
User->>EnhancerGenerator: Request to enhance PrismaClient
EnhancerGenerator->>EnhancerGenerator: Validate targetRuntime
EnhancerGenerator->>PolicyGenerator: Initialize policy checks
PolicyGenerator->>PermissionCheck: Execute permission check
PermissionCheck-->>PolicyGenerator: Return permission result
PolicyGenerator-->>EnhancerGenerator: Return policy results
EnhancerGenerator-->>User: Return enhanced PrismaClient
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
|
Fixes #1672 |
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/runtime/package.jsonis excluded by!**/*.json
Files selected for processing (38)
- packages/runtime/src/enhancements/edge/create-enhancement.ts (1 hunks)
- packages/runtime/src/enhancements/edge/default-auth.ts (1 hunks)
- packages/runtime/src/enhancements/edge/delegate.ts (1 hunks)
- packages/runtime/src/enhancements/edge/index.ts (1 hunks)
- packages/runtime/src/enhancements/edge/logger.ts (1 hunks)
- packages/runtime/src/enhancements/edge/omit.ts (1 hunks)
- packages/runtime/src/enhancements/edge/password.ts (1 hunks)
- packages/runtime/src/enhancements/edge/policy/check-utils.ts (1 hunks)
- packages/runtime/src/enhancements/edge/policy/handler.ts (1 hunks)
- packages/runtime/src/enhancements/edge/policy/index.ts (1 hunks)
- packages/runtime/src/enhancements/edge/policy/policy-utils.ts (1 hunks)
- packages/runtime/src/enhancements/edge/promise.ts (1 hunks)
- packages/runtime/src/enhancements/edge/proxy.ts (1 hunks)
- packages/runtime/src/enhancements/edge/query-utils.ts (1 hunks)
- packages/runtime/src/enhancements/edge/types.ts (1 hunks)
- packages/runtime/src/enhancements/edge/utils.ts (1 hunks)
- packages/runtime/src/enhancements/edge/where-visitor.ts (1 hunks)
- packages/runtime/src/enhancements/node/create-enhancement.ts (2 hunks)
- packages/runtime/src/enhancements/node/default-auth.ts (1 hunks)
- packages/runtime/src/enhancements/node/delegate.ts (2 hunks)
- packages/runtime/src/enhancements/node/index.ts (1 hunks)
- packages/runtime/src/enhancements/node/omit.ts (1 hunks)
- packages/runtime/src/enhancements/node/password.ts (1 hunks)
- packages/runtime/src/enhancements/node/policy/check-utils.ts (1 hunks)
- packages/runtime/src/enhancements/node/policy/handler.ts (4 hunks)
- packages/runtime/src/enhancements/node/policy/index.ts (1 hunks)
- packages/runtime/src/enhancements/node/policy/policy-utils.ts (2 hunks)
- packages/runtime/src/enhancements/node/promise.ts (1 hunks)
- packages/runtime/src/enhancements/node/proxy.ts (2 hunks)
- packages/runtime/src/enhancements/node/query-utils.ts (1 hunks)
- packages/runtime/src/enhancements/node/types.ts (2 hunks)
- packages/runtime/src/enhancements/node/utils.ts (1 hunks)
- packages/runtime/src/enhancements/node/where-visitor.ts (1 hunks)
- packages/runtime/src/index.ts (1 hunks)
- packages/runtime/src/types.ts (2 hunks)
- packages/schema/src/plugins/enhancer/enhance/index.ts (1 hunks)
- packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts (1 hunks)
- packages/testtools/src/schema.ts (1 hunks)
Files skipped from review due to trivial changes (25)
- packages/runtime/src/enhancements/edge/create-enhancement.ts
- packages/runtime/src/enhancements/edge/default-auth.ts
- packages/runtime/src/enhancements/edge/delegate.ts
- packages/runtime/src/enhancements/edge/index.ts
- packages/runtime/src/enhancements/edge/logger.ts
- packages/runtime/src/enhancements/edge/omit.ts
- packages/runtime/src/enhancements/edge/password.ts
- packages/runtime/src/enhancements/edge/policy/handler.ts
- packages/runtime/src/enhancements/edge/policy/index.ts
- packages/runtime/src/enhancements/edge/policy/policy-utils.ts
- packages/runtime/src/enhancements/edge/promise.ts
- packages/runtime/src/enhancements/edge/query-utils.ts
- packages/runtime/src/enhancements/edge/types.ts
- packages/runtime/src/enhancements/edge/utils.ts
- packages/runtime/src/enhancements/edge/where-visitor.ts
- packages/runtime/src/enhancements/node/default-auth.ts
- packages/runtime/src/enhancements/node/omit.ts
- packages/runtime/src/enhancements/node/password.ts
- packages/runtime/src/enhancements/node/policy/index.ts
- packages/runtime/src/enhancements/node/policy/policy-utils.ts
- packages/runtime/src/enhancements/node/promise.ts
- packages/runtime/src/enhancements/node/query-utils.ts
- packages/runtime/src/enhancements/node/utils.ts
- packages/runtime/src/enhancements/node/where-visitor.ts
- packages/testtools/src/schema.ts
Additional comments not posted (27)
packages/runtime/src/enhancements/node/index.ts (1)
1-1: Verify the impact of the export path change on the codebase.Ensure that all import statements referencing the
crossmodule from this file are updated to match the new path.Run the following script to verify the import statements:
packages/runtime/src/index.ts (2)
3-3: Verify the impact of exporting theenhancemodule on the codebase.Ensure that the change does not break any existing code that depends on the previously exported
enhancementsmodule.Run the following script to verify the impact:
Verification successful
No issues found with the export change to the
enhancemodule.The transition from exporting the
enhancementsmodule to theenhancemodule does not negatively impact the codebase, as there are no dependencies on the former and the latter is correctly integrated.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of exporting the `enhance` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --type typescript -g '!index.ts' $'from \'@core/runtime/enhancements\'' # Test 2: Search for the usage of the `enhance` module. Expect: Only valid occurrences. rg --type typescript -A 5 $'from \'@core/runtime/enhance\''Length of output: 214
Script:
#!/bin/bash # Description: Verify the impact of exporting the `enhance` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --glob '!index.ts' 'from \'@core/runtime/enhancements\'' --type-add 'ts:*.ts' # Test 2: Search for the usage of the `enhance` module. Expect: Only valid occurrences. rg --glob '!index.ts' 'from \'@core/runtime/enhance\'' --type-add 'ts:*.ts' -A 5Length of output: 93
Script:
#!/bin/bash # Description: Verify the impact of exporting the `enhance` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --glob '!index.ts' "from '@core/runtime/enhancements'" --type ts # Test 2: Search for the usage of the `enhance` module. Expect: Only valid occurrences. rg --glob '!index.ts' "from '@core/runtime/enhance'" --type ts -A 5Length of output: 151
2-2: Verify the impact of exporting thecrossmodule on the codebase.Ensure that the change does not break any existing code that depends on the previously exported
enhancementsmodule.Run the following script to verify the impact:
Verification successful
No impact on the codebase from exporting the
crossmodule.The change from exporting the
enhancementsmodule to thecrossmodule does not affect any existing code, as there are no imports of these modules elsewhere in the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of exporting the `cross` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --type typescript -g '!index.ts' $'from \'@core/runtime/enhancements\'' # Test 2: Search for the usage of the `cross` module. Expect: Only valid occurrences. rg --type typescript -A 5 $'from \'@core/runtime/cross\''Length of output: 212
Script:
#!/bin/bash # Description: Verify the impact of exporting the `cross` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --glob '!index.ts' 'from \'@core/runtime/enhancements\'' --type ts # Test 2: Search for the usage of the `cross` module. Expect: Only valid occurrences. rg --glob '!index.ts' 'from \'@core/runtime/cross\'' --type ts -A 5Length of output: 93
Script:
#!/bin/bash # Description: Verify the impact of exporting the `cross` module on the codebase. # Test 1: Search for the usage of the `enhancements` module. Expect: No occurrences. rg --glob '!index.ts' "from '@core/runtime/enhancements'" --type ts # Test 2: Search for the usage of the `cross` module. Expect: Only valid occurrences. rg --glob '!index.ts' "from '@core/runtime/cross'" --type ts -A 5Length of output: 149
packages/runtime/src/enhancements/edge/policy/check-utils.ts (1)
1-4: LGTM!The code changes are approved.
packages/runtime/src/enhancements/node/create-enhancement.ts (2)
2-4: LGTM!The changes to the import statements are approved.
11-11: LGTM!The change to the import statement is approved.
packages/runtime/src/types.ts (6)
3-3: LGTM!The code changes are approved.
96-101: LGTM!The code changes are approved.
106-136: LGTM!The code changes are approved.
141-143: LGTM!The code changes are approved.
148-148: LGTM!The code changes are approved.
150-168: LGTM!The code changes are approved.
packages/runtime/src/enhancements/node/policy/check-utils.ts (2)
10-20: LGTM!The code changes are approved.
22-124: LGTM!The code changes are approved. The function is well-implemented and handles various scenarios appropriately. The input validation and type checking ensure that only valid inputs are processed. The function combines the permission constraint with runtime filters, if provided, to perform a comprehensive permission check. The use of a constraint solver to check the satisfiability of the constraint is a good approach.
packages/runtime/src/enhancements/node/types.ts (2)
2-2: LGTM!The code change is approved.
260-262: LGTM!The code change is approved.
packages/runtime/src/enhancements/node/proxy.ts (2)
3-4: LGTM!The import path changes are approved.
5-5: Verify the impact of removing theErrorTransformertype export.The removal of the
ErrorTransformertype export suggests a potential shift in how error transformations are handled within the module.Please run the following script to verify that the removal of the
ErrorTransformertype export does not break any existing code:Verification successful
No impact from removing
ErrorTransformertype exportThe removal of the
ErrorTransformertype export fromproxy.tsdoes not affect any existing code, as there are no imports of this type found in the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: # Verify that the removal of the `ErrorTransformer` type export does not break any existing code. # Expected results: # The script should not find any occurrences of the `ErrorTransformer` type being imported from this file. # Search for any imports of the `ErrorTransformer` type from this file rg --type typescript $'from \'\.\/proxy\';(\n|.)*ErrorTransformer'Length of output: 345
Script:
#!/bin/bash # Description: # Verify that the removal of the `ErrorTransformer` type export does not break any existing code. # Expected results: # The script should not find any occurrences of the `ErrorTransformer` type being imported from this file. # Search for any imports of the `ErrorTransformer` type from this file rg --type typescript 'from\s+\./proxy.*\bErrorTransformer\b'Length of output: 97
Script:
#!/bin/bash # Description: # Verify that the removal of the `ErrorTransformer` type export does not break any existing code. # Expected results: # The script should not find any occurrences of the `ErrorTransformer` type being imported from this file. # Search for any imports of the `ErrorTransformer` type from this file rg --glob '*.ts' 'from\s+\./proxy.*\bErrorTransformer\b'Length of output: 58
packages/schema/src/plugins/enhancer/enhance/index.ts (2)
97-100: LGTM!The runtime validation logic is correctly implemented. It ensures that the
EnhancerGeneratorclass only operates under the specified environments, enhancing robustness by preventing misconfigurations.
106-106: LGTM!The import statement is correctly updated to dynamically include the
targetRuntime, allowing for more flexible imports based on the runtime context.packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts (1)
104-107: LGTM!The changes to the import declarations for
type PolicyDefandtype PermissionCheckerConstraintlook good. Importing these types from a separate module (${RUNTIME_PACKAGE}/enhancements/node) improves the modularity and organization of the codebase.packages/runtime/src/enhancements/node/delegate.ts (3)
5-5: LGTM!The import path has been updated to reflect the new directory structure.
16-16: LGTM!The import path has been updated to reflect the new directory structure.
17-17: LGTM!The import path has been updated to reflect the new directory structure.
packages/runtime/src/enhancements/node/policy/handler.ts (3)
Line range hint
8-20: LGTM!The code changes are approved.
28-28: LGTM!The code changes are approved.
1641-1643: LGTM!The refactoring of the
checkmethod looks good. Delegating the permission checking responsibility to thecheckPermissionfunction simplifies the control flow and enhances the maintainability of the code.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/server/package.jsonis excluded by!**/*.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!**/*.yaml
Files selected for processing (1)
- packages/runtime/src/enhancements/node/types.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/runtime/src/enhancements/node/types.ts
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- packages/runtime/res/enhance-edge.d.ts (1 hunks)
- packages/runtime/res/enhance-edge.js (1 hunks)
- packages/runtime/src/edge.ts (1 hunks)
- packages/runtime/src/enhance-edge.d.ts (1 hunks)
- packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
- packages/schema/src/plugins/plugin-utils.ts (1 hunks)
Files skipped from review due to trivial changes (3)
- packages/runtime/res/enhance-edge.d.ts
- packages/runtime/src/edge.ts
- packages/runtime/src/enhance-edge.d.ts
Additional context used
Biome
packages/runtime/res/enhance-edge.js
[error] 1-1: Redundant use strict directive.
The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.(lint/suspicious/noRedundantUseStrict)
Additional comments not posted (3)
packages/schema/src/plugins/plugin-utils.ts (1)
43-46: Approve addition of./enhance-edgeentry.The addition of the
./enhance-edgeentry in theensureDefaultOutputFolderfunction is a good enhancement for supporting edge runtime environments.packages/schema/src/plugins/enhancer/enhance/index.ts (2)
Line range hint
97-133: Approve changes for runtime-specific enhancement file generation.The modifications to generate separate enhancement files for 'node' and 'edge' runtimes are well-implemented and align with the PR's objectives to enhance runtime compatibility.
Line range hint
97-133: Verify dynamic import paths and integration with runtime environments.Ensure that the dynamic import paths and the overall integration with the runtime environments are correctly implemented and tested.
Consider running integration tests to confirm that the enhancements work as expected in both 'node' and 'edge' environments.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/runtime/package.jsonis excluded by!**/*.json
Files selected for processing (1)
- packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/plugins/trpc/tests/projects/t3-trpc-v10/package.jsonis excluded by!**/*.json
Files selected for processing (1)
- packages/plugins/trpc/tests/projects/t3-trpc-v10/src/pages/index.tsx (1 hunks)
Additional context used
Biome
packages/plugins/trpc/tests/projects/t3-trpc-v10/src/pages/index.tsx
[error] 16-21: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 22-22: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (1)
packages/plugins/trpc/tests/projects/t3-trpc-v10/src/pages/index.tsx (1)
7-10: Enhanced data structure inpostsTransformedquery.The modification to include both
idandtitlein thepostsTransformedquery enhances the data structure, which is crucial for rendering the posts correctly in the UI. Ensure that the data structure returned by the query matches the expected format in the UI components.Run the following script to verify the data structure:
Verification successful
Data structure usage verified for
postsTransformedquery.The
postsTransformedquery is correctly utilized in the UI to render a list of posts, confirming that the data structure includes bothidandtitleas intended. This aligns with the enhancement goals for improved data handling and rendering. No further action is required.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the data structure returned by the `postsTransformed` query. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type typescript -A 5 $'postsTransformed'Length of output: 79
Script:
#!/bin/bash # Description: Verify the data structure returned by the `postsTransformed` query. # Find all TypeScript files and search for `postsTransformed` usage. fd --extension ts --extension tsx --exec rg 'postsTransformed' {}Length of output: 238
packages/plugins/trpc/tests/projects/t3-trpc-v10/src/pages/index.tsx
Outdated
Show resolved
Hide resolved
packages/plugins/trpc/tests/projects/t3-trpc-v10/src/pages/index.tsx
Outdated
Show resolved
Hide resolved
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.
The SAT solver "logical-solver" uses MiniSAT which uses "eval" thus breaking edge runtime. This change mutes the
check()functionality when targeting edge runtime.A "runtime" option is added to "@core/enhance" plugin. It defaults to "node" and can be set to "edge".