Skip to content

Commit

Permalink
Clean up and convert ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhtr committed Jun 5, 2020
1 parent 712fe47 commit 2523eff
Show file tree
Hide file tree
Showing 16 changed files with 901 additions and 7 deletions.
55 changes: 55 additions & 0 deletions maas-schemas-ts/src/core/components/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,61 @@ export interface ItineraryStateBrand {
readonly ItineraryState: unique symbol;
}

// SubscriptionIntentState
// The life-cycle state of an subscription intent
export type SubscriptionIntentState = t.Branded<
string &
(
| 'START'
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'AUTH'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
| 'FINISHED'
),
SubscriptionIntentStateBrand
>;
export const SubscriptionIntentState = t.brand(
t.intersection([
t.string,
t.union([
t.literal('START'),
t.literal('DETAILS'),
t.literal('CUSTOMISATION'),
t.literal('PAYMENT'),
t.literal('AUTH'),
t.literal('VERIFICATION'),
t.literal('CANCELLED'),
t.literal('CANCELLED_WITH_ERRORS'),
t.literal('FINISHED'),
]),
]),
(
x,
): x is t.Branded<
string &
(
| 'START'
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'AUTH'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
| 'FINISHED'
),
SubscriptionIntentStateBrand
> => true,
'SubscriptionIntentState',
);
export interface SubscriptionIntentStateBrand {
readonly SubscriptionIntentState: unique symbol;
}

// State
// The default export. More information at the top.
export type State = t.Branded<unknown, StateBrand>;
Expand Down
186 changes: 186 additions & 0 deletions maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
undefined
MaaS subscription intent schema
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
*/

import * as t from 'io-ts';
import * as State_ from 'maas-schemas-ts/core/components/state';
import * as Units_ from 'maas-schemas-ts/core/components/units';
import * as StateLog_ from 'maas-schemas-ts/core/components/state-log';

type Defined =
| Record<string, unknown>
| Array<unknown>
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);

export const schemaId =
'http://maasglobal.com/maas-backend/subscriptions/subscription-intent.json';

// ItemId
// The purpose of this remains a mystery
export type ItemId = t.Branded<string, ItemIdBrand>;
export const ItemId = t.brand(
t.string,
(x): x is t.Branded<string, ItemIdBrand> =>
(typeof x !== 'string' || x.length >= 1) &&
(typeof x !== 'string' || x.length <= 255),
'ItemId',
);
export interface ItemIdBrand {
readonly ItemId: unique symbol;
}

// SubscriptionIntentCreate
// The purpose of this remains a mystery
export type SubscriptionIntentCreate = t.Branded<
{
planId?: ItemId;
planAddons?: Array<ItemId>;
state?: State_.SubscriptionIntentState;
startTime?: Units_.Time;
} & {
planId: Defined;
planAddons: Defined;
},
SubscriptionIntentCreateBrand
>;
export const SubscriptionIntentCreate = t.brand(
t.intersection([
t.partial({
planId: ItemId,
planAddons: t.array(ItemId),
state: State_.SubscriptionIntentState,
startTime: Units_.Time,
}),
t.type({
planId: Defined,
planAddons: Defined,
}),
]),
(
x,
): x is t.Branded<
{
planId?: ItemId;
planAddons?: Array<ItemId>;
state?: State_.SubscriptionIntentState;
startTime?: Units_.Time;
} & {
planId: Defined;
planAddons: Defined;
},
SubscriptionIntentCreateBrand
> => true,
'SubscriptionIntentCreate',
);
export interface SubscriptionIntentCreateBrand {
readonly SubscriptionIntentCreate: unique symbol;
}

// SubscriptionIntentBase
// The purpose of this remains a mystery
export type SubscriptionIntentBase = t.Branded<
{
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: ItemId;
nextPlanAddons?: Array<ItemId>;
prevPlanId?: ItemId;
prevPlanAddons?: Array<ItemId>;
startTime?: Units_.Time;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
modified?: Units_.Time;
} & {
identityId: Defined;
subscriptionId: Defined;
nextPlanId: Defined;
nextPlanAddons: Defined;
},
SubscriptionIntentBaseBrand
>;
export const SubscriptionIntentBase = t.brand(
t.intersection([
t.partial({
id: Units_.Uuid,
identityId: Units_.IdentityId,
subscriptionId: Units_.IdentityId,
nextPlanId: ItemId,
nextPlanAddons: t.array(ItemId),
prevPlanId: ItemId,
prevPlanAddons: t.array(ItemId),
startTime: Units_.Time,
state: State_.SubscriptionIntentState,
stateLog: StateLog_.StateLog,
created: Units_.Time,
modified: Units_.Time,
}),
t.type({
identityId: Defined,
subscriptionId: Defined,
nextPlanId: Defined,
nextPlanAddons: Defined,
}),
]),
(
x,
): x is t.Branded<
{
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: ItemId;
nextPlanAddons?: Array<ItemId>;
prevPlanId?: ItemId;
prevPlanAddons?: Array<ItemId>;
startTime?: Units_.Time;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
modified?: Units_.Time;
} & {
identityId: Defined;
subscriptionId: Defined;
nextPlanId: Defined;
nextPlanAddons: Defined;
},
SubscriptionIntentBaseBrand
> => true,
'SubscriptionIntentBase',
);
export interface SubscriptionIntentBaseBrand {
readonly SubscriptionIntentBase: unique symbol;
}

// SubscriptionIntent
// The default export. More information at the top.
export type SubscriptionIntent = t.Branded<unknown, SubscriptionIntentBrand>;
export const SubscriptionIntent = t.brand(
t.unknown,
(x): x is t.Branded<unknown, SubscriptionIntentBrand> => true,
'SubscriptionIntent',
);
export interface SubscriptionIntentBrand {
readonly SubscriptionIntent: unique symbol;
}

export default SubscriptionIntent;

// Success
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
undefined
Request schema for subscriptions-intents-create
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
*/

import * as t from 'io-ts';
import * as Units_ from 'maas-schemas-ts/core/components/units';
import * as SubscriptionIntent_ from 'maas-schemas-ts/maas-backend/subscriptions/subscription-intent';
import * as ApiCommon_ from 'maas-schemas-ts/core/components/api-common';

type Defined =
| Record<string, unknown>
| Array<unknown>
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);

export const schemaId =
'http://maasglobal.com/maas-backend/subscriptions/subscriptions-intents-create/request.json';

// Request
// The default export. More information at the top.
export type Request = t.Branded<
{
customerId?: Units_.IdentityId;
userId?: Units_.IdentityId;
payload?: SubscriptionIntent_.SubscriptionIntentCreate;
headers?: ApiCommon_.Headers;
} & {
customerId: Defined;
userId: Defined;
payload: Defined;
},
RequestBrand
>;
export const Request = t.brand(
t.intersection([
t.partial({
customerId: Units_.IdentityId,
userId: Units_.IdentityId,
payload: SubscriptionIntent_.SubscriptionIntentCreate,
headers: ApiCommon_.Headers,
}),
t.type({
customerId: Defined,
userId: Defined,
payload: Defined,
}),
]),
(
x,
): x is t.Branded<
{
customerId?: Units_.IdentityId;
userId?: Units_.IdentityId;
payload?: SubscriptionIntent_.SubscriptionIntentCreate;
headers?: ApiCommon_.Headers;
} & {
customerId: Defined;
userId: Defined;
payload: Defined;
},
RequestBrand
> => true,
'Request',
);
export interface RequestBrand {
readonly Request: unique symbol;
}

export default Request;

// Success
Loading

0 comments on commit 2523eff

Please sign in to comment.