Skip to content

Commit

Permalink
use type alias for contract source id
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Dec 14, 2023
1 parent 56ea3ee commit efe215d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
7 changes: 6 additions & 1 deletion packages/marlowe-object/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export { Action, Deposit, Notify, Choice } from "./actions.js";
export { ChoiceName, ChoiceId, Bound, ChosenNum } from "./choices.js";
export { Reference, Label } from "./reference.js";
export {
Reference,
Label,
ContractSourceId,
ContractSourceIdGuard,
} from "./reference.js";
export { Address, Role, Party } from "./participants.js";
export { Payee, PayeeAccount, PayeeParty, AccountId } from "./payee.js";

Expand Down
12 changes: 11 additions & 1 deletion packages/marlowe-object/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export type Label = string;

export const LabelGuard: t.Type<Label> = t.string;

/**
* A label for one of the {@link ObjectType}
* @category Object
*/
export type ContractSourceId = string;

export const ContractSourceIdGuard: t.Type<ContractSourceId> = t.string;

/**
* A reference to an {@link ObjectType}.
* @category Object
Expand All @@ -20,4 +28,6 @@ export interface Reference {
* {@link !io-ts-usage | Dynamic type guard} for the {@link Reference | reference type}.
* @category Object
*/
export const ReferenceGuard: t.Type<Reference> = t.type({ ref: t.string });
export const ReferenceGuard: t.Type<Reference> = t.type({
ref: ContractSourceIdGuard,
});
31 changes: 18 additions & 13 deletions packages/runtime/client/rest/src/contract/endpoints/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, Contract } 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) => {
Expand All @@ -42,7 +47,7 @@ export const createContractSources = (axiosInstance: AxiosInstance) => {
};

export interface GetContractBySourceIdRequest {
contractSourceId: BuiltinByteString;
contractSourceId: ContractSourceId;
expand?: boolean;
}

Expand Down Expand Up @@ -73,15 +78,15 @@ export const getContractSourceById =
};

export interface GetContractSourceAdjacencyRequest {
contractSourceId: BuiltinByteString;
contractSourceId: ContractSourceId;
}

export interface GetContractSourceAdjacencyResponse {
results: BuiltinByteString[];
results: ContractSourceId[];
}

const GetContractSourceAdjacencyResponseGuard: t.Type<GetContractSourceAdjacencyResponse> =
t.type({ results: t.array(G.BuiltinByteString) });
t.type({ results: t.array(ContractSourceIdGuard) });

export const getContractSourceAdjacency =
(axiosInstance: AxiosInstance) =>
Expand All @@ -103,15 +108,15 @@ export const getContractSourceAdjacency =
};

export interface GetContractSourceClosureRequest {
contractSourceId: BuiltinByteString;
contractSourceId: ContractSourceId;
}

export interface GetContractSourceClosureResponse {
results: BuiltinByteString[];
results: ContractSourceId[];
}

const GetContractSourceClosureResponseGuard: t.Type<GetContractSourceClosureResponse> =
t.type({ results: t.array(G.BuiltinByteString) });
t.type({ results: t.array(ContractSourceIdGuard) });

export const getContractSourceClosure =
(axiosInstance: AxiosInstance) =>
Expand Down

0 comments on commit efe215d

Please sign in to comment.