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 Apr 16, 2020
1 parent d897f6c commit 212f0f6
Show file tree
Hide file tree
Showing 17 changed files with 902 additions and 8 deletions.
2 changes: 1 addition & 1 deletion maas-schemas-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maas-schemas-ts",
"version": "13.1.0",
"version": "13.2.0",
"description": "TypeScript types and io-ts validators for maas-schemas",
"main": "index.js",
"files": [
Expand Down
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 212f0f6

Please sign in to comment.