-
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
Changes from all commits
641c5db
93aaaaf
652a201
be3e2ad
2ecf468
fc0a315
9dd619a
6efc9d5
d29184f
3c831c0
56ea3ee
efe215d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### @marlowe.io/runtime-rest-client | ||
|
||
- PLT-7701: Extend the rest client with procedure `getContractSourceById`. (Implemented in [PR-128](https://github.com/input-output-hk/marlowe-ts-sdk/pull/128)) | ||
- PLT-7702: Extend the rest client with procedure `getContractSourceAdjacency`. (Implemented in [PR-128](https://github.com/input-output-hk/marlowe-ts-sdk/pull/128)) | ||
- PLT-7703: Extend the rest client with procedure `getContractSourceClosure`. (Implemented in [PR-128](https://github.com/input-output-hk/marlowe-ts-sdk/pull/128)) | ||
- PLT-8427: Extend the rest client with procedure `getNextStepsForContract`. (Implemented in [PR-128](https://github.com/input-output-hk/marlowe-ts-sdk/pull/128)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,26 @@ import * as E from "fp-ts/lib/Either.js"; | |
import { pipe } from "fp-ts/lib/function.js"; | ||
import { formatValidationErrors } from "jsonbigint-io-ts-reporters"; | ||
|
||
import { BuiltinByteString } from "@marlowe.io/language-core-v1"; | ||
import { Bundle, Label } from "@marlowe.io/marlowe-object"; | ||
import { Contract } from "@marlowe.io/language-core-v1"; | ||
import { | ||
Bundle, | ||
Label, | ||
ContractSourceId, | ||
ContractSourceIdGuard, | ||
} from "@marlowe.io/marlowe-object"; | ||
import { AxiosInstance } from "axios"; | ||
|
||
export interface CreateContractSourcesResponse { | ||
contractSourceId: BuiltinByteString; | ||
contractSourceId: ContractSourceId; | ||
intermediateIds: { | ||
[key: Label]: BuiltinByteString; | ||
[key: Label]: ContractSourceId; | ||
}; | ||
} | ||
|
||
const CreateContractSourcesResponseGuard: t.Type<CreateContractSourcesResponse> = | ||
t.type({ | ||
contractSourceId: G.BuiltinByteString, | ||
intermediateIds: t.record(t.string, G.BuiltinByteString), | ||
contractSourceId: ContractSourceIdGuard, | ||
intermediateIds: t.record(t.string, ContractSourceIdGuard), | ||
}); | ||
|
||
export const createContractSources = (axiosInstance: AxiosInstance) => { | ||
|
@@ -40,3 +45,94 @@ export const createContractSources = (axiosInstance: AxiosInstance) => { | |
); | ||
}; | ||
}; | ||
|
||
export interface GetContractBySourceIdRequest { | ||
contractSourceId: ContractSourceId; | ||
expand?: boolean; | ||
} | ||
|
||
export type GetContractBySourceIdResponse = Contract; | ||
|
||
const GetContractBySourceIdResponseGuard: t.Type<GetContractBySourceIdResponse> = | ||
G.Contract; | ||
|
||
export const getContractSourceById = | ||
(axiosInstance: AxiosInstance) => | ||
async ({ | ||
contractSourceId, | ||
expand, | ||
}: GetContractBySourceIdRequest): Promise<GetContractBySourceIdResponse> => { | ||
const response = await axiosInstance.get( | ||
`/contracts/sources/${encodeURIComponent(contractSourceId)}`, | ||
{ params: { expand } } | ||
); | ||
Comment on lines
+65
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return pipe( | ||
GetContractBySourceIdResponseGuard.decode(response.data), | ||
E.match( | ||
(e) => { | ||
throw formatValidationErrors(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}, | ||
(e) => e | ||
) | ||
); | ||
}; | ||
bjornkihlberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface GetContractSourceAdjacencyRequest { | ||
contractSourceId: ContractSourceId; | ||
} | ||
|
||
export interface GetContractSourceAdjacencyResponse { | ||
results: ContractSourceId[]; | ||
} | ||
|
||
const GetContractSourceAdjacencyResponseGuard: t.Type<GetContractSourceAdjacencyResponse> = | ||
t.type({ results: t.array(ContractSourceIdGuard) }); | ||
|
||
export const getContractSourceAdjacency = | ||
(axiosInstance: AxiosInstance) => | ||
async ({ | ||
contractSourceId, | ||
}: GetContractSourceAdjacencyRequest): Promise<GetContractSourceAdjacencyResponse> => { | ||
const response = await axiosInstance.get( | ||
`/contracts/sources/${encodeURIComponent(contractSourceId)}/adjacency` | ||
); | ||
return pipe( | ||
GetContractSourceAdjacencyResponseGuard.decode(response.data), | ||
E.match( | ||
(e) => { | ||
throw formatValidationErrors(e); | ||
}, | ||
(e) => e | ||
) | ||
); | ||
}; | ||
bjornkihlberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface GetContractSourceClosureRequest { | ||
contractSourceId: ContractSourceId; | ||
} | ||
|
||
export interface GetContractSourceClosureResponse { | ||
results: ContractSourceId[]; | ||
} | ||
|
||
const GetContractSourceClosureResponseGuard: t.Type<GetContractSourceClosureResponse> = | ||
t.type({ results: t.array(ContractSourceIdGuard) }); | ||
|
||
export const getContractSourceClosure = | ||
(axiosInstance: AxiosInstance) => | ||
async ({ | ||
contractSourceId, | ||
}: GetContractSourceClosureRequest): Promise<GetContractSourceClosureResponse> => { | ||
const response = await axiosInstance.get( | ||
`/contracts/sources/${encodeURIComponent(contractSourceId)}/closure` | ||
); | ||
return pipe( | ||
GetContractSourceClosureResponseGuard.decode(response.data), | ||
E.match( | ||
(e) => { | ||
throw formatValidationErrors(e); | ||
}, | ||
(e) => e | ||
) | ||
); | ||
}; | ||
bjornkihlberg marked this conversation as resolved.
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 comment block for
ContractSourceId
appears to be a duplicate of the one forLabel
. It should be updated to accurately describeContractSourceId
.Committable suggestion