-
Notifications
You must be signed in to change notification settings - Fork 11
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
PLT-9368: Strict mode for runtime-lifecycle #180
Conversation
WalkthroughThe overarching change focuses on enhancing type safety and standardizing request object structures across various operations in a Node.js context. This involves transitioning from passing individual parameters to using object parameters with named properties for function calls. Additionally, there's an introduction of new type guards and modifications to support dynamic type checking, reflecting a move towards more robust and error-resistant code practices. Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
packages/language/core/v1/package.json
is excluded by:!**/*.json
packages/marlowe-object/package.json
is excluded by:!**/*.json
Files selected for processing (25)
- examples/nodejs/src/experimental-features/applicable-inputs.ts (1 hunks)
- examples/nodejs/src/marlowe-object-flow.ts (2 hunks)
- examples/survey-workshop/custodian/index.js (2 hunks)
- examples/vesting-flow/index.html (1 hunks)
- jsdelivr-npm-importmap.js (2 hunks)
- packages/adapter/src/io-ts.ts (2 hunks)
- packages/runtime/client/rest/src/contract/endpoints/collection.ts (6 hunks)
- packages/runtime/client/rest/src/contract/endpoints/singleton.ts (3 hunks)
- packages/runtime/client/rest/src/contract/endpoints/sources.ts (4 hunks)
- packages/runtime/client/rest/src/contract/index.ts (2 hunks)
- packages/runtime/client/rest/src/contract/next/endpoint.ts (2 hunks)
- packages/runtime/client/rest/src/contract/transaction/endpoints/collection.ts (4 hunks)
- packages/runtime/client/rest/src/contract/transaction/endpoints/singleton.ts (3 hunks)
- packages/runtime/client/rest/src/index.ts (15 hunks)
- packages/runtime/client/rest/src/payout/endpoints/collection.ts (2 hunks)
- packages/runtime/client/rest/src/payout/endpoints/singleton.ts (1 hunks)
- packages/runtime/client/rest/src/withdrawal/endpoints/collection.ts (3 hunks)
- packages/runtime/client/rest/src/withdrawal/endpoints/singleton.ts (2 hunks)
- packages/runtime/core/src/textEnvelope.ts (1 hunks)
- packages/runtime/lifecycle/src/browser/index.ts (3 hunks)
- packages/runtime/lifecycle/src/generic/contracts.ts (3 hunks)
- packages/runtime/lifecycle/src/index.ts (2 hunks)
- packages/runtime/lifecycle/src/nodejs/index.ts (1 hunks)
- packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (2 hunks)
- packages/wallet/src/browser/index.ts (2 hunks)
Additional comments: 60
packages/runtime/lifecycle/src/nodejs/index.ts (1)
- 36-36: The
mkRestClient
function is correctly called with thestrict
parameter, ensuring that the strict mode setting is propagated. This is a good practice for maintaining consistency in how strict type checks are applied across different parts of the application.packages/runtime/client/rest/src/payout/endpoints/singleton.ts (1)
- 29-32: The definition of
GetPayoutByIdRequestGuard
correctly usesassertGuardEqual
to ensure that theGetPayoutByIdRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.packages/runtime/core/src/textEnvelope.ts (1)
- 45-46: The introduction of
HexTransactionWitnessSetGuard
as a type guard forHexTransactionWitnessSet
is a straightforward and effective way to ensure that values assigned to variables of typeHexTransactionWitnessSet
are indeed strings. This is a good practice for enhancing type safety in the application.packages/runtime/client/rest/src/contract/index.ts (3)
- 46-46: The export of
SubmitContractRequest
from./endpoints/singleton.js
is correctly implemented, ensuring that this type is available for use in other parts of the application. This is a good practice for modularizing type definitions and promoting code reuse.- 50-52: The export of transaction-related request types from
./transaction/endpoints/singleton.js
is correctly implemented. This modular approach to exporting types enhances code maintainability and readability by clearly separating concerns.- 57-57: The addition of
GetTransactionsForContractRequest
to the exports from./transaction/endpoints/collection.js
is a good practice, ensuring that this type is available for use where needed in the application. It promotes a consistent and modular approach to managing type definitions.packages/runtime/lifecycle/src/index.ts (1)
- 75-75: The
mkRestClient
function is correctly called with thestrict
parameter, ensuring that the strict mode setting is propagated. This is a good practice for maintaining consistency in how strict type checks are applied across different parts of the application.examples/survey-workshop/custodian/index.js (2)
- 25-27: The modification to call
restClient.getTransactionsForContract
with an object parameter is a good practice. It improves code readability and maintainability by clearly indicating what each parameter represents.- 38-41: Similarly, the modification to call
restClient.getContractTransactionById
with an object parameter enhances code readability and maintainability. Using named properties in function calls makes the code more self-documenting and easier to understand.packages/runtime/lifecycle/src/browser/index.ts (1)
- 93-93: The
mkRestClient
function is correctly called with thestrict
parameter, ensuring that the strict mode setting is propagated. This is a good practice for maintaining consistency in how strict type checks are applied across different parts of the application, even in a browser environment.packages/adapter/src/io-ts.ts (2)
- 100-102: The introduction of the
strictDynamicTypeCheck
function is a good practice for validating the type of thestrict
parameter in a dynamically typed context. This function enhances type safety by ensuring thatstrict
is always a boolean.- 104-110: The addition of the
InvalidTypeError
class is a good practice for error handling. It extends theError
class with a constructor that includes parameters for errors and a message, allowing for more descriptive error messages related to type validation failures.packages/runtime/client/rest/src/contract/next/endpoint.ts (1)
- 54-66: The definition of
GetNextStepsForContractRequestGuard
correctly usesassertGuardEqual
to ensure that theGetNextStepsForContractRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.packages/runtime/client/rest/src/withdrawal/endpoints/singleton.ts (2)
- 34-41: The definition of
GetWithdrawalByIdRequestGuard
correctly usesassertGuardEqual
to ensure that theGetWithdrawalByIdRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.- 52-58: Similarly, the definition of
SubmitWithdrawalRequestGuard
correctly usesassertGuardEqual
to ensure that theSubmitWithdrawalRequest
type aligns with its runtime validation. This enhances type safety by ensuring that the data structures used in the application are correctly validated at runtime.packages/runtime/client/rest/src/contract/endpoints/singleton.ts (2)
- 74-84: The definition of
SubmitContractRequestGuard
correctly usesassertGuardEqual
to ensure that theSubmitContractRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.- 87-87: The replacement of
submitContractViaAxios
withsubmitContract
and the update to thePUT
type to include new parameters and guards forHexTransactionWitnessSet
andHexTransactionWitnessSetGuard
are correctly implemented. This enhances the clarity and maintainability of the code by using more descriptive function names and ensuring type safety through the use of guards.packages/runtime/client/rest/src/contract/transaction/endpoints/singleton.ts (2)
- 39-49: The definition of
GetContractTransactionByIdRequestGuard
correctly usesassertGuardEqual
to ensure that theGetContractTransactionByIdRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.- 73-85: Similarly, the definition of
SubmitContractTransactionRequestGuard
correctly usesassertGuardEqual
to ensure that theSubmitContractTransactionRequest
type aligns with its runtime validation. This enhances type safety by ensuring that the data structures used in the application are correctly validated at runtime.packages/runtime/client/rest/src/payout/endpoints/collection.ts (1)
- 35-47: The definition of
GetPayoutsRequestGuard
correctly usesassertGuardEqual
to ensure that theGetPayoutsRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.packages/runtime/client/rest/src/contract/endpoints/sources.ts (4)
- 23-28: The definition of
CreateContractSourcesRequestGuard
correctly usesassertGuardEqual
to ensure that theCreateContractSourcesRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.- 68-73: The definition of
GetContractBySourceIdRequestGuard
correctly usesassertGuardEqual
to ensure that theGetContractBySourceIdRequest
type aligns with its runtime validation. This enhances type safety by ensuring that the data structures used in the application are correctly validated at runtime.- 106-107: Similarly, the definition of
GetContractSourceAdjacencyRequestGuard
correctly usesassertGuardEqual
to ensure that theGetContractSourceAdjacencyRequest
type aligns with its runtime validation. This is a good practice for maintaining type safety and ensuring that the data structures used in the application are correctly validated at runtime.- 139-140: The definition of
GetContractSourceClosureRequestGuard
correctly usesassertGuardEqual
to ensure that theGetContractSourceClosureRequest
type aligns with its runtime validation. This enhances type safety by ensuring that the data structures used in the application are correctly validated at runtime.jsdelivr-npm-importmap.js (4)
- 27-28: The addition of the mapping for
@marlowe.io/language-core-v1/contract
is correctly implemented.- 31-32: The addition of the mapping for
@marlowe.io/language-core-v1/inputs
is correctly implemented.- 35-36: The addition of the mapping for
@marlowe.io/language-core-v1/participants
is correctly implemented.- 83-84: The addition of the mapping for
@marlowe.io/marlowe-object/object
is correctly implemented.packages/runtime/client/rest/src/contract/transaction/endpoints/collection.ts (4)
- 18-18: The addition of
AddressBech32Guard
is correctly implemented and enhances type safety.- 34-39: The addition of
ItemRangeGuard
,PageGuard
, andInputGuard
declarations is correctly implemented, improving the structure and type safety of the code.- 88-103: The modifications to the
GetTransactionsForContractRequest
interface and the addition ofGetTransactionsForContractRequestGuard
are correctly implemented, aligning with best practices for type safety and code maintainability.- 145-162: The modifications to the
ApplyInputsToContractRequest
interface and the addition ofApplyInputsToContractRequestGuard
are correctly implemented, enhancing type safety and code structure.packages/wallet/src/browser/index.ts (3)
- 3-3: The addition of
io-ts
import is correctly implemented and is essential for runtime type validation.- 6-6: The addition of
assertGuardEqual
andproxy
imports from@marlowe.io/adapter/io-ts
is correctly implemented, supporting the new type guard functionality.- 27-31: The introduction of
SupportedWalletNameGuard
usingio-ts
for type validation is correctly implemented, enhancing type safety within the module.packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (2)
- 252-252: The modification to the
getContractById
function call to pass an object with thecontractId
property is correctly implemented, aligning with the updated API signature.- 271-271: The modification to the
getContractById
function call withingetMarloweStatefromAnActiveContract
to pass an object with thecontractId
property is correctly implemented, enhancing code readability and maintainability.packages/runtime/lifecycle/src/generic/contracts.ts (3)
- 59-67: The modification to the
getTransactionsForContract
function call to pass an object with thecontractId
property is correctly implemented, aligning with the updated API signature.- 137-139: The modification to the
createContractSources
function call to pass an object with thebundle
property is correctly implemented, enhancing code readability and maintainability.- 153-156: The modification to the
submitContract
function call to pass an object with thecontractId
andtxEnvelope
properties is correctly implemented, aligning with the updated API signature.examples/vesting-flow/index.html (2)
- 143-143: The modification to the
getContractById
function call to pass an object with thecontractId
property is correctly implemented, aligning with the updated API signature.- 150-157: The modifications to the
getTransactionsForContract
andgetContractTransactionById
function calls to pass objects with named properties are correctly implemented, enhancing code readability and maintainability.examples/nodejs/src/experimental-features/applicable-inputs.ts (1)
- 125-125: The change to call
restClient.getContractById
with an object containingcontractId
as a property, instead of passingcontractId
directly, aligns with the PR's goal of improving type safety and developer experience by standardizing function calls.examples/nodejs/src/marlowe-object-flow.ts (1)
- 588-596: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [591-615]
The modifications to use object parameters for
getContractById
andcreateContractSources
calls are consistent with the PR's objectives to improve type safety and standardize function calls.packages/runtime/client/rest/src/contract/endpoints/collection.ts (3)
- 35-35: The addition of
AddressBech32Guard
to the imports supports the PR's objective of improving type safety through stricter type checking.- 52-52: The addition of
RoleNameGuard
to the imports further enhances type safety by ensuring role names adhere to expected formats.- 80-88: The definition of
GetContractsRequestGuard
correctly uses the newly importedAddressBech32Guard
andRoleNameGuard
, aligning with the PR's focus on type safety.packages/runtime/client/rest/src/index.ts (13)
- 32-39: The addition of
CompatibleRuntimeVersionGuard
,RuntimeVersion
,InvalidTypeError
, andstrictDynamicTypeCheck
imports aligns with the PR's objective to enhance type safety and introduce strict mode functionality.- 108-108: The change in the
createContractSources
method signature to accept aSources.CreateContractSourcesRequest
object instead of aContractBundle
improves the method's clarity and type safety by using structured request objects.- 154-155: The modification of the
getContractById
method to accept a request object enhances the method's usability and consistency with other SDK methods.- 161-161: Updating the
submitContract
method to take a request object aligns with the PR's goal of improving parameter handling and type safety.- 171-171: The change in the
getTransactionsForContract
method signature to use a request object is a positive step towards standardizing method interfaces across the SDK.- 191-191: Modifying the
submitContractTransaction
method to accept a request object is consistent with the PR's objectives of enhancing type safety and improving developer experience.- 202-202: The update to the
getContractTransactionById
method signature to use a request object instead of individual parameters is a good practice for improving code readability and maintainability.- 231-231: Changing the
getWithdrawalById
method to accept a request object is in line with the PR's aim to standardize method calls and improve type safety.- 237-237: The modification of the
submitWithdrawal
method to use a request object instead of individual parameters aligns with the PR's objectives and enhances the method's clarity.- 256-291: The introduction of
mkRestClientArgumentDynamicTypeCheck
and the modifications tomkRestClient
to include dynamic type checking and strict mode are significant improvements. They enforce type safety and provide developers with more informative error messages, aligning with the PR's goals. However, ensure that the performance impact of these checks, especially in non-strict mode, is minimal and documented.- 317-327: The implementation of strict type checking in the
getContracts
method, usingContracts.GetContractsRequestGuard
, is a good practice that enhances type safety and error handling in the SDK.- 341-351: Implementing strict type checking in the
getContractById
method usingContract.GetContractByIdRequest
guard is consistent with the PR's objectives to improve type safety and developer experience.- 355-367: The addition of strict type checking in the
buildCreateContractTx
method usingContracts.BuildCreateContractTxRequestGuard
aligns with the PR's goal of enhancing type safety and improving error handling.
@@ -122,7 +122,7 @@ export async function getApplicableActions( | |||
contractId: ContractId, | |||
environment?: Environment | |||
): Promise<ApplicableAction[]> { | |||
const contractDetails = await restClient.getContractById(contractId); | |||
const contractDetails = await restClient.getContractById({ contractId }); |
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 use of await
inside getApplicableActions
without a try-catch block for error handling could lead to unhandled promise rejections if restClient.getContractById
fails. Consider adding error handling to improve robustness.
+ try {
const contractDetails = await restClient.getContractById({ contractId });
+ } catch (error) {
+ console.error("Failed to get contract details:", error);
+ throw error; // Rethrow or handle as appropriate for your application logic
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const contractDetails = await restClient.getContractById({ contractId }); | |
try { | |
const contractDetails = await restClient.getContractById({ contractId }); | |
} catch (error) { | |
console.error("Failed to get contract details:", error); | |
throw error; // Rethrow or handle as appropriate for your application logic | |
} |
contractId: ContractId | ||
): Promise<ValidationResults> { | ||
// First we try to fetch the contract details and the required tags | ||
const contractDetails = | ||
await lifecycle.restClient.getContractById(contractId); | ||
const contractDetails = await lifecycle.restClient.getContractById({ | ||
contractId, | ||
}); | ||
|
||
const scheme = extractSchemeFromTags(contractDetails.tags); | ||
|
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.
📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [591-615]
Consider adding error handling for the asynchronous calls to getContractById
, createContractSources
, and getContractSourceById
to manage potential failures gracefully.
+ try {
const contractDetails = await lifecycle.restClient.getContractById({ contractId });
...
const { contractSourceId } = await lifecycle.restClient.createContractSources({ bundle: contractBundle });
...
const initialContract = await lifecycle.restClient.getContractSourceById({ contractSourceId });
+ } catch (error) {
+ console.error("Error fetching contract details or sources:", error);
+ throw error; // Rethrow or handle as appropriate for your application logic
+ }
strict: unknown = true | ||
) { | ||
if (!strictDynamicTypeCheck(strict)) { | ||
throw new InvalidTypeError( | ||
[], | ||
`Invalid type for argument 'strict', expected boolean but got ${strict}` | ||
); |
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 validation for the strict
parameter uses a custom type check (strictDynamicTypeCheck
) but does not correctly check the type of strict
. It should directly check if strict
is a boolean instead of using a custom function that is not shown in this context.
- if (!strictDynamicTypeCheck(strict)) {
+ if (typeof strict !== 'boolean') {
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
strict: unknown = true | |
) { | |
if (!strictDynamicTypeCheck(strict)) { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); | |
strict: unknown = true | |
) { | |
if (typeof strict !== 'boolean') { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); |
if (!strictDynamicTypeCheck(strict)) { | ||
throw new InvalidTypeError( | ||
[], | ||
`Invalid type for argument 'strict', expected boolean but got ${strict}` | ||
); |
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 validation for the strict
parameter within the mkRuntimeLifecycle
function does not directly check if strict
is a boolean. Instead, it relies on a custom type check (strictDynamicTypeCheck
) that is not shown in this context. Directly checking the type of strict
would be more straightforward and reliable.
- if (!strictDynamicTypeCheck(strict)) {
+ if (typeof strict !== 'boolean') {
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if (!strictDynamicTypeCheck(strict)) { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); | |
if (typeof strict !== 'boolean') { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); |
if (!strictDynamicTypeCheck(strict)) { | ||
throw new InvalidTypeError( | ||
[], | ||
`Invalid type for argument 'strict', expected boolean but got ${strict}` | ||
); |
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 validation for the strict
parameter within the mkRuntimeLifecycle
function does not directly check if strict
is a boolean. Instead, it relies on a custom type check (strictDynamicTypeCheck
) that is not shown in this context. Directly checking the type of strict
would be more straightforward and reliable.
- if (!strictDynamicTypeCheck(strict)) {
+ if (typeof strict !== 'boolean') {
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if (!strictDynamicTypeCheck(strict)) { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); | |
if (typeof strict !== 'boolean') { | |
throw new InvalidTypeError( | |
[], | |
`Invalid type for argument 'strict', expected boolean but got ${strict}` | |
); |
@bjornkihlberg can you squash all these |
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.
Just checked the code, looks good
}, | ||
"./contract": { | ||
"import": "./dist/esm/contract.js", | ||
"require": "./dist/bundled/cjs/contract.cjs", | ||
"types": "./dist/esm/contract.d.ts" | ||
}, | ||
"./participants": { | ||
"import": "./dist/esm/participants.js", | ||
"require": "./dist/bundled/cjs/participants.cjs", | ||
"types": "./dist/esm/participants.d.ts" | ||
}, | ||
"./inputs": { | ||
"import": "./dist/esm/inputs.js", | ||
"require": "./dist/bundled/cjs/inputs.cjs", | ||
"types": "./dist/esm/inputs.d.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.
Why are you exporting these?
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.
I had to in order to be able to use the rest client from the browser. Maybe we can avoid it. I'll look into it.
import { ContractGuard } from "@marlowe.io/language-core-v1/contract"; | ||
import { RoleNameGuard } from "@marlowe.io/language-core-v1/participants"; |
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.
these should be
import * as G from "@marlowe.io/language-core-v1/guards
G.Contract
G.RoleName
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.
This may remove the need for some of the exported modules.
`Invalid argument to getContracts(${request})` | ||
); | ||
} else { | ||
const test: typeof request = result.right; |
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.
this seems unused
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.
It's unused at runtime but it helps ensure that you are using the correct guard. I think there are better ways of solving this. I'm going to look into it.
if (strict) { | ||
const result = Contract.GetContractByIdRequest.decode(request); | ||
if (result._tag === "Left") { | ||
throw new InvalidTypeError( | ||
result.left, | ||
`Invalid argument to getContractById(${request})` | ||
); | ||
} else { | ||
const test: typeof request = result.right; | ||
} | ||
} |
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.
I think this pattern could be captured by a function assertRequest(methodName, guard, request, strict)
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.
Yes, I was thinking the same.
6c57cbe
to
0a5e457
Compare
0a5e457
to
c443dbc
Compare
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
packages/marlowe-object/package.json
is excluded by:!**/*.json
Files selected for processing (26)
- changelog.d/20240126_162752_bjorn.wilhelm.kihlberg_PLT_9368.md (1 hunks)
- examples/nodejs/src/experimental-features/applicable-inputs.ts (1 hunks)
- examples/nodejs/src/marlowe-object-flow.ts (2 hunks)
- examples/survey-workshop/custodian/index.js (2 hunks)
- examples/vesting-flow/index.html (1 hunks)
- jsdelivr-npm-importmap.js (1 hunks)
- packages/adapter/src/io-ts.ts (2 hunks)
- packages/runtime/client/rest/src/contract/endpoints/collection.ts (7 hunks)
- packages/runtime/client/rest/src/contract/endpoints/singleton.ts (3 hunks)
- packages/runtime/client/rest/src/contract/endpoints/sources.ts (4 hunks)
- packages/runtime/client/rest/src/contract/index.ts (2 hunks)
- packages/runtime/client/rest/src/contract/next/endpoint.ts (2 hunks)
- packages/runtime/client/rest/src/contract/transaction/endpoints/collection.ts (4 hunks)
- packages/runtime/client/rest/src/contract/transaction/endpoints/singleton.ts (3 hunks)
- packages/runtime/client/rest/src/index.ts (15 hunks)
- packages/runtime/client/rest/src/payout/endpoints/collection.ts (2 hunks)
- packages/runtime/client/rest/src/payout/endpoints/singleton.ts (1 hunks)
- packages/runtime/client/rest/src/withdrawal/endpoints/collection.ts (3 hunks)
- packages/runtime/client/rest/src/withdrawal/endpoints/singleton.ts (2 hunks)
- packages/runtime/core/src/textEnvelope.ts (1 hunks)
- packages/runtime/lifecycle/src/browser/index.ts (3 hunks)
- packages/runtime/lifecycle/src/generic/contracts.ts (3 hunks)
- packages/runtime/lifecycle/src/index.ts (2 hunks)
- packages/runtime/lifecycle/src/nodejs/index.ts (1 hunks)
- packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (2 hunks)
- packages/wallet/src/browser/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (24)
- changelog.d/20240126_162752_bjorn.wilhelm.kihlberg_PLT_9368.md
- examples/nodejs/src/experimental-features/applicable-inputs.ts
- examples/nodejs/src/marlowe-object-flow.ts
- examples/survey-workshop/custodian/index.js
- examples/vesting-flow/index.html
- jsdelivr-npm-importmap.js
- packages/adapter/src/io-ts.ts
- packages/runtime/client/rest/src/contract/endpoints/collection.ts
- packages/runtime/client/rest/src/contract/endpoints/singleton.ts
- packages/runtime/client/rest/src/contract/endpoints/sources.ts
- packages/runtime/client/rest/src/contract/index.ts
- packages/runtime/client/rest/src/contract/transaction/endpoints/collection.ts
- packages/runtime/client/rest/src/contract/transaction/endpoints/singleton.ts
- packages/runtime/client/rest/src/payout/endpoints/collection.ts
- packages/runtime/client/rest/src/payout/endpoints/singleton.ts
- packages/runtime/client/rest/src/withdrawal/endpoints/collection.ts
- packages/runtime/client/rest/src/withdrawal/endpoints/singleton.ts
- packages/runtime/core/src/textEnvelope.ts
- packages/runtime/lifecycle/src/browser/index.ts
- packages/runtime/lifecycle/src/generic/contracts.ts
- packages/runtime/lifecycle/src/index.ts
- packages/runtime/lifecycle/src/nodejs/index.ts
- packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts
- packages/wallet/src/browser/index.ts
Additional comments: 7
packages/runtime/client/rest/src/contract/next/endpoint.ts (2)
- 54-66: The
GetNextStepsForContractRequestGuard
correctly usesio-ts
for runtime type validation, ensuring that the request object adheres to the expected structure. This is a good practice for enhancing type safety in dynamic environments.- 67-67: The
getNextStepsForContract
function correctly decodes and validates the response data using theGetNextStepsForContractResponseGuard
, throwing formatted validation errors if decoding fails. This approach is consistent with best practices for error handling and data validation.packages/runtime/client/rest/src/index.ts (5)
- 32-39: The addition of
CompatibleRuntimeVersionGuard
,RuntimeVersion
,InvalidTypeError
, andstrictDynamicTypeCheck
imports supports the new strict mode functionality, aligning with the PR's objective to enhance type safety and developer experience.- 108-108: The modification of the
createContractSources
method signature to accept a request object instead of individual parameters is a positive change. It improves the method's usability and consistency with the rest of the API, aligning with the PR's objectives.- 256-261: The
mkRestClientArgumentDynamicTypeCheck
function provides a runtime check for thebaseURL
argument, ensuring it's a string when strict mode is enabled. This is a good practice for type safety.- 280-291: The dynamic type checking for
strict
andbaseURL
arguments inmkRestClient
enhances error reporting and type safety, aligning with the PR's objectives to improve developer experience through stricter runtime checks.- 317-327: The implementation of strict mode checks in methods like
getContracts
is consistent and correctly throwsInvalidTypeError
when the request object does not match the expected type. This approach significantly improves error handling and developer feedback.
@@ -1,15 +1,18 @@ | |||
import { AxiosInstance } from "axios"; | |||
import * as E from "fp-ts/lib/Either.js"; | |||
import * as TE from "fp-ts/lib/TaskEither.js"; | |||
import * as G from "@marlowe.io/language-core-v1/guards"; |
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 import * as G from "@marlowe.io/language-core-v1/guards";
is not used in the file.
- import * as G from "@marlowe.io/language-core-v1/guards";
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import * as G from "@marlowe.io/language-core-v1/guards"; |
import { Environment, Party } from "@marlowe.io/language-core-v1"; | ||
import { Next } from "@marlowe.io/language-core-v1/next"; | ||
import { stringify } from "qs"; | ||
import { DecodingError } from "@marlowe.io/adapter/codec"; | ||
import { posixTimeToIso8601 } from "@marlowe.io/adapter/time"; | ||
import { assertGuardEqual, proxy } from "@marlowe.io/adapter/io-ts"; | ||
import * as t from "io-ts/lib/index.js"; |
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 assertGuardEqual
import is not used in this file. Consider removing it to clean up unused imports.
- import { assertGuardEqual, proxy } from "@marlowe.io/adapter/io-ts";
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import * as t from "io-ts/lib/index.js"; | |
import * as t from "io-ts/lib/index.js"; |
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- packages/adapter/src/io-ts.ts (2 hunks)
- packages/runtime/client/rest/src/contract/endpoints/collection.ts (7 hunks)
- packages/runtime/client/rest/src/index.ts (10 hunks)
Files skipped from review as they are similar to previous changes (2)
- packages/adapter/src/io-ts.ts
- packages/runtime/client/rest/src/contract/endpoints/collection.ts
Additional comments: 11
packages/runtime/client/rest/src/index.ts (11)
- 14-14: The removal of
ContractBundle
import is not directly visible in the provided code, but its usage seems to have been replaced with request objects in method signatures. Ensure that all instances whereContractBundle
was previously used have been appropriately updated.Verification successful
The verification process focused on ensuring that the removal or modification of
ContractBundle
inrest/src/index.ts
was handled appropriately. The presence ofContractBundle
in other parts of the project, as revealed by the script output, does not directly indicate an issue with the specific changes inrest/src/index.ts
. The original review comment remains relevant, emphasizing the need to ensure that all instances whereContractBundle
was previously used in the context ofrest/src/index.ts
have been appropriately updated. Based on the information provided, there is no direct evidence to suggest that the changes inrest/src/index.ts
regardingContractBundle
were incorrectly done. Therefore, the verification process concludes with the understanding that the specific changes made torest/src/index.ts
are consistent with the project's current state and usage patterns ofContractBundle
.* 33-40: New imports for `CompatibleRuntimeVersionGuard`, `RuntimeVersion`, `InvalidTypeError`, and `strictDynamicTypeCheck` have been added. Verify that these are correctly utilized in the context of enabling strict mode and dynamic type checking throughout the file. * 110-110: The `createContractSources` method signature has been modified to accept a `Sources.CreateContractSourcesRequest` object instead of a `ContractBundle`. This change aligns with the PR's objective to standardize function calls and improve code readability by using request objects. * 155-157: The `getContractById` method signature has been updated to accept a `Contract.GetContractByIdRequest` object. This change enhances the method's clarity and consistency with other updated method signatures. * 163-163: The `submitContract` method now takes a `Contract.SubmitContractRequest` object, aligning with the PR's goal of using request objects for better parameter handling and type safety. * 173-173: The `getTransactionsForContract` method signature has been updated to use a `Transactions.GetTransactionsForContractRequest` object, which is consistent with the PR's aim to improve function call standardization. * 193-193: The `submitContractTransaction` method signature change to accept a `Transaction.SubmitContractTransactionRequest` object is in line with the PR's objectives to enhance type safety and parameter handling. * 233-233: The `getWithdrawalById` method signature has been modified to accept a `Withdrawal.GetWithdrawalByIdRequest` object, further standardizing method signatures across the SDK. * 239-239: The `submitWithdrawal` method signature has been updated to use a `Withdrawal.SubmitWithdrawalRequest` object, aligning with the PR's goals for improved parameter handling and type safety. * 258-277: The addition of `mkRestClientArgumentDynamicTypeCheck` and `withDynamicTypeCheck` functions introduces dynamic type checking based on the `strict` mode setting. This is a crucial part of the PR's objective to enhance type safety and developer experience by providing more informative error messages during development. Ensure that these functions are correctly implemented and used throughout the file. * 255-313: > 📝 **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [291-324]Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining references to ContractBundle in the project. rg "ContractBundle" --type tsLength of output: 1292
The
mkRestClient
function has been overloaded to support an optionalstrict
boolean parameter, enabling dynamic type checking. This change is central to the PR's goal of introducing a strict mode for runtime lifecycle management. Verify that the strict mode is correctly applied and that the dynamic type checks are performed as expected.
Examples
Examples of improvements to developer experience
Summary by CodeRabbit
New Features
@marlowe.io
namespace, facilitating easier module access and management.Refactor
Documentation
Bug Fixes