-
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-7701, PLT-7702, PLT-7703, PLT-8427: Implement remaining 1-1 endpoints #128
Conversation
WalkthroughThe codebase has been updated to enhance contract source management and processing within a REST client context. New functions for retrieving contract sources by ID, adjacency, and closure have been added, along with type guards for response validation. The client interface now includes methods for these functions, and the Changes
Poem
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 X ? TipsChat with CodeRabbit Bot (
|
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: 9
Configuration used: CodeRabbit UI
Files selected for processing (3)
- packages/runtime/client/rest/src/contract/endpoints/sources.ts (2 hunks)
- packages/runtime/client/rest/src/contract/next/endpoint.ts (3 hunks)
- packages/runtime/client/rest/src/index.ts (10 hunks)
Additional comments: 7
packages/runtime/client/rest/src/contract/endpoints/sources.ts (3)
44-52: The
GetContractBySourceIdRequest
andGetContractBySourceIdResponse
interfaces are well-defined, and the type guardGetContractBySourceIdResponseGuard
is correctly usingG.Contract
for validation.75-103: The
GetContractSourceAdjacencyRequest
andGetContractSourceAdjacencyResponse
interfaces are correctly defined, and the type guardGetContractSourceAdjacencyResponseGuard
is properly implemented usingt.array(G.BuiltinByteString)
.105-114: The
GetContractSourceClosureRequest
andGetContractSourceClosureResponse
interfaces are correctly defined, and the type guardGetContractSourceClosureResponseGuard
is properly implemented usingt.array(G.BuiltinByteString)
.packages/runtime/client/rest/src/contract/next/endpoint.ts (3)
1-6: The imports for
io-ts
andlanguage-core-v1/guards
are correctly added to support the new type definitions and runtime type checking.47-54: The
GetNextStepsForContractRequest
interface andGetNextStepsForContractResponse
type are well-defined and align with the new endpoint's requirements.58-90: The
getNextStepsForContract
function is implemented correctly, using the new request interface and response type, and includes proper error handling with runtime type checking.packages/runtime/client/rest/src/index.ts (1)
- 90-126: The implementation of new methods in the
RestClient
interface aligns with the PR objectives. Ensure that the corresponding implementations inmkRestClient
are correct and consistent with the interface definitions.
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 (1)
- changelog.d/20231213_145052_bjorn.wilhelm.kihlberg_PLT_7701.md (1 hunks)
Additional comments: 1
changelog.d/20231213_145052_bjorn.wilhelm.kihlberg_PLT_7701.md (1)
- 1-6: The changelog entries are clear and correctly reference the PR where the new procedures were implemented.
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.
How are you testing these endpoints, or more important how can I test them?
I don't mean the integration testing that should happen later, I'm referring to manual testing. I don't see any change to the rest-client-flow
example with the addition of these endpoints.
Take a look at this PR, where I add instructions on how to manually test the createContractSources
endpoint
}; | ||
|
||
export interface GetContractSourceAdjacencyRequest { | ||
contractSourceId: BuiltinByteString; |
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 believe a type alias might clarify the intent.
type ContractSourceId = string
// or
type ContractSourceId = BuiltinByteString
We could asses also if a Branded type makes sense to show that not all strings are the same
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.
Have we figured out yet how we want to do branded types?
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, using t.brand from io-ts
} | ||
|
||
export interface GetContractSourceAdjacencyResponse { | ||
results: BuiltinByteString[]; |
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 shows the importance of the type alias
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.
Fair point.
Yes, I just need to write a flow for these end points. |
Signed-off-by: Björn Kihlberg <[email protected]>
e655d42
to
3c831c0
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: 9
Configuration used: CodeRabbit UI
Files selected for processing (6)
- changelog.d/20231213_145052_bjorn.wilhelm.kihlberg_PLT_7701.md (1 hunks)
- examples/js/poc-helpers.js (1 hunks)
- examples/merkleization-flow/index.html (1 hunks)
- packages/runtime/client/rest/src/contract/endpoints/sources.ts (2 hunks)
- packages/runtime/client/rest/src/contract/next/endpoint.ts (1 hunks)
- packages/runtime/client/rest/src/index.ts (10 hunks)
Files skipped from review as they are similar to previous changes (2)
- changelog.d/20231213_145052_bjorn.wilhelm.kihlberg_PLT_7701.md
- packages/runtime/client/rest/src/contract/next/endpoint.ts
Additional comments: 7
examples/js/poc-helpers.js (2)
39-45: The null check added to
getRuntimeUrl
is a good defensive programming practice to prevent potential null reference errors. This change ensures that the function will not throw an error ifruntimeUrlInput
is null when trying to access itsvalue
property.39-45: While the change to
getRuntimeUrl
is approved, it's important to ensure that this change is in line with the broader objectives of the PR, which is to implement new endpoints related to contract sources. If this change is part of a larger set of UI updates to support the new endpoints, it would be beneficial to mention this context in the PR description for clarity.packages/runtime/client/rest/src/contract/endpoints/sources.ts (2)
7-7: The addition of the
Contract
import aligns with the new features being implemented for contract source management.44-133: The implementation of the new functions for contract source management is consistent with the PR objectives and follows established patterns for making GET requests and using type guards.
packages/runtime/client/rest/src/index.ts (3)
87-126: The addition of new methods
createContractSources
,getContractSourceById
,getContractSourceAdjacency
,getContractSourceClosure
, andgetNextStepsForContract
to theRestClient
interface aligns with the PR objective to enhance contract source management capabilities.312-326: The implementation of the new methods in the
mkRestClient
function correctly corresponds to the updatedRestClient
interface.30-30: The import of
Next
from "./contract/next/endpoint.js" has been added. Verify that all instances ofContractNext
have been replaced withNext
to maintain consistency.Verification successful
The shell script executed a search for any remaining usages of
ContractNext
and did not produce any output. This suggests that there are no instances ofContractNext
left in the codebase, which would imply that the replacement withNext
is consistent throughout the files that were searched.Given this information, it seems that the change from
ContractNext
toNext
has been successfully applied across the codebase, at least in the context of the files thatrg
would have searched through (which is typically all text files in the repository).Since the script did not find any occurrences of
ContractNext
, I can conclude that the replacement has been done correctly, and there are no inconsistencies in the files that were checked.The import of
Next
from "./contract/next/endpoint.js" has been added, and based on the search results, all instances ofContractNext
have been replaced withNext
as no occurrences were found in the codebase.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining usages of ContractNext that should have been replaced with Next. rg 'ContractNext' --files-with-matchesLength of output: 38
@@ -40,3 +40,94 @@ export const createContractSources = (axiosInstance: AxiosInstance) => { | |||
); | |||
}; | |||
}; | |||
|
|||
export interface GetContractBySourceIdRequest { | |||
contractSourceId: BuiltinByteString; |
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 BuiltinByteString
directly as a type for contractSourceId
is noted. Consider revisiting the previous discussion on using a type alias or branded type to clarify intent and ensure type safety.
}; | ||
|
||
export interface GetContractSourceAdjacencyRequest { | ||
contractSourceId: BuiltinByteString; |
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.
Reconsider the implementation of a type alias for BuiltinByteString
to improve code readability and maintainability, as previously discussed.
const runtimeGood = await restClient.healthcheck(); | ||
if (!runtimeGood) throw "Healthcheck failed!"; | ||
|
||
debugger; |
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 debugger;
statements are typically used for development and should not be present in production code. Consider removing them before merging.
const contract_pt1 = { | ||
let: "x", | ||
be: 5n, | ||
then: { ref: contract_pt2_Label }, |
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 object definition for contract_pt1
is incorrect. JavaScript objects should consist of key-value pairs.
- const contract_pt1 = {
- let: "x",
- be: 5n,
- then: { ref: contract_pt2_Label },
- };
+ const contract_pt1 = {
+ "let": "x",
+ "be": 5n,
+ "then": { "ref": contract_pt2_Label },
+ };
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 contract_pt1 = { | |
let: "x", | |
be: 5n, | |
then: { ref: contract_pt2_Label }, | |
const contract_pt1 = { | |
"let": "x", | |
"be": 5n, | |
"then": { "ref": contract_pt2_Label }, |
await restClient.createContractSources(contract_pt1_Label, [ | ||
{ type: "contract", label: contract_pt1_Label, contract_pt1 }, | ||
{ type: "contract", label: contract_pt2_Label, contract_pt2 }, | ||
{ type: "contract", label: contract_pt3_Label, contract_pt3 }, | ||
]); |
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 variables contract_pt1
, contract_pt2
, and contract_pt3
are not being passed correctly to createContractSources
. They should be passed as objects.
- { type: "contract", label: contract_pt1_Label, contract_pt1 },
- { type: "contract", label: contract_pt2_Label, contract_pt2 },
- { type: "contract", label: contract_pt3_Label, contract_pt3 },
+ { type: "contract", label: contract_pt1_Label, contract: contract_pt1 },
+ { type: "contract", label: contract_pt2_Label, contract: contract_pt2 },
+ { type: "contract", label: contract_pt3_Label, contract: contract_pt3 },
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.
await restClient.createContractSources(contract_pt1_Label, [ | |
{ type: "contract", label: contract_pt1_Label, contract_pt1 }, | |
{ type: "contract", label: contract_pt2_Label, contract_pt2 }, | |
{ type: "contract", label: contract_pt3_Label, contract_pt3 }, | |
]); | |
await restClient.createContractSources(contract_pt1_Label, [ | |
{ type: "contract", label: contract_pt1_Label, contract: contract_pt1 }, | |
{ type: "contract", label: contract_pt2_Label, contract: contract_pt2 }, | |
{ type: "contract", label: contract_pt3_Label, contract: contract_pt3 }, | |
]); |
const runtimeGood = await restClient.healthcheck(); | ||
if (!runtimeGood) throw "Healthcheck failed!"; |
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 healthcheck
method is called on the restClient
, but it's not clear if this method exists or what it returns. Assuming it's correct, the error handling should be improved.
- const runtimeGood = await restClient.healthcheck();
- if (!runtimeGood) throw "Healthcheck failed!";
+ try {
+ const runtimeGood = await restClient.healthcheck();
+ if (!runtimeGood) {
+ console.error("Healthcheck failed!");
+ // Handle the error appropriately
+ }
+ } catch (error) {
+ console.error("Healthcheck failed with error:", error);
+ // Handle the error appropriately
+ }
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 runtimeGood = await restClient.healthcheck(); | |
if (!runtimeGood) throw "Healthcheck failed!"; | |
try { | |
const runtimeGood = await restClient.healthcheck(); | |
if (!runtimeGood) { | |
console.error("Healthcheck failed!"); | |
// Handle the error appropriately | |
} | |
} catch (error) { | |
console.error("Healthcheck failed with error:", error); | |
// Handle the error appropriately | |
} |
@@ -195,13 +234,6 @@ export interface RestClient { | |||
*/ | |||
healthcheck(): Promise<Boolean>; |
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 healthcheck
method in mkRestClient
returns a promise that resolves to a boolean, which is inconsistent with the healthcheck
method in the FPTSRestAPI
interface that returns a TE.TaskEither
. Consider aligning the return types for consistency.
@@ -470,7 +514,7 @@ export interface ContractsAPI { | |||
/** | |||
* @see {@link } | |||
*/ | |||
next: ContractNext.GET; | |||
next: Next.GET; |
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 next
property in the ContractsAPI
interface is assigned a Next.GET
type, but there is no corresponding implementation in the mkFPTSRestClient
function. Add the missing implementation to match the interface.
+ next: Next.getViaAxios(axiosInstance),
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.
next: Next.GET; | |
next: Next.getViaAxios(axiosInstance); |
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 (1)
- examples/rest-client-flow/index.html (1 hunks)
Files skipped from review due to trivial changes (1)
- examples/rest-client-flow/index.html
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: 3
Configuration used: CodeRabbit UI
Files selected for processing (3)
- packages/marlowe-object/src/index.ts (1 hunks)
- packages/marlowe-object/src/reference.ts (2 hunks)
- packages/runtime/client/rest/src/contract/endpoints/sources.ts (2 hunks)
Additional comments: 3
packages/marlowe-object/src/index.ts (1)
- 3-8: The changes to the export statements in
index.ts
correctly include the newContractSourceId
andContractSourceIdGuard
exports from./reference.js
, which align with the PR objectives to extend the runtime client's REST interface for contract source management.packages/marlowe-object/src/reference.ts (2)
11-17: The introduction of
ContractSourceId
andContractSourceIdGuard
is consistent with the PR objectives to enhance contract source management capabilities.31-33: The update to
Reference
andReferenceGuard
to useContractSourceId
andContractSourceIdGuard
enhances type safety and clarity, aligning with the PR's goal of improving contract source management.
/** | ||
* A label for one of the {@link ObjectType} | ||
* @category Object | ||
*/ |
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 comment block for ContractSourceId
appears to be a duplicate of the one for Label
. It should be updated to accurately describe ContractSourceId
.
/**
- * A label for one of the {@link ObjectType}
+ * An identifier for a contract source within the system
* @category Object
*/
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.
/** | |
* A label for one of the {@link ObjectType} | |
* @category Object | |
*/ | |
/** | |
* An identifier for a contract source within the system | |
* @category Object | |
*/ |
GetContractBySourceIdResponseGuard.decode(response.data), | ||
E.match( | ||
(e) => { | ||
throw formatValidationErrors(e); |
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.
Consider improving error handling by wrapping validation errors in a user-friendly message or a custom error type to avoid exposing internal details and to provide more informative messages to the caller.
Also applies to: 103-103, 133-133
const response = await axiosInstance.get( | ||
`/contracts/sources/${encodeURIComponent(contractSourceId)}`, | ||
{ params: { expand } } | ||
); |
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.
Consider adding error handling for the HTTP request to handle network errors or non-200 status codes.
Also applies to: 96-98, 126-128
This PR
getContractSourceById
#70getContractSourceAdjacency
#71getContractSourceClosure
#72getNextStepsForContract
#75Summary by CodeRabbit
Summary by CodeRabbit
New Features
Enhancements
RestClient
interface to include new methods for enhanced contract interactions.Refactor