UNPKG

sextant

Version:

Chart application flows, then implement them in code

516 lines (431 loc) 13.5 kB
export type Maybe<T> = T | null; export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: string; String: string; Boolean: boolean; Int: number; Float: number; }; export type GetUsers__GET_USERS = {}; export type GetUsers__GET_USER = {}; export type GetUsers__USER_FROM_COGNITO = {}; export type GetUsers__USERS = {}; export type Post = { id: Scalars['ID']; title: Scalars['String']; slug: Scalars['String']; }; export type GetPosts__POSTS = { posts: Array<Post>; }; export type GetPosts__GET_POSTS = { search: Scalars['String']; }; export type GetPosts__NO_POSTS_FOUND = {}; export type GetFriendsOfUser__GET_FRIENDS_OF_USER = { userId: Scalars['ID']; }; export type GetFriendsOfUser__FRIENDS_OF_USER = {}; export type GetComments__COMMENTS = { comments: Array<Scalars['String']>; }; export type GetComments__GET_COMMENTS = {}; export interface SextantFeatures { 'getUsers': { scenarios: | "success" actors: { 'frontend': { from: { 'lambda': { in: | GetUsers__USERS & { type: "USERS" } out: | GetUsers__GET_USERS & { type: "GET_USERS" } } } to: { 'lambda': { in: | GetUsers__GET_USERS & { type: "GET_USERS" } out: | GetUsers__USERS & { type: "USERS" } } } } 'lambda': { from: { 'frontend': { in: | GetUsers__GET_USERS & { type: "GET_USERS" } out: | GetUsers__USERS & { type: "USERS" } } 'cognito': { in: | GetUsers__USER_FROM_COGNITO & { type: "USER_FROM_COGNITO" } out: | GetUsers__GET_USER & { type: "GET_USER" } } } to: { 'frontend': { in: | GetUsers__USERS & { type: "USERS" } out: | GetUsers__GET_USERS & { type: "GET_USERS" } } 'cognito': { in: | GetUsers__GET_USER & { type: "GET_USER" } out: | GetUsers__USER_FROM_COGNITO & { type: "USER_FROM_COGNITO" } } } } 'cognito': { from: { 'lambda': { in: | GetUsers__GET_USER & { type: "GET_USER" } out: | GetUsers__USER_FROM_COGNITO & { type: "USER_FROM_COGNITO" } } } to: { 'lambda': { in: | GetUsers__USER_FROM_COGNITO & { type: "USER_FROM_COGNITO" } out: | GetUsers__GET_USER & { type: "GET_USER" } } } } } } 'getPosts': { scenarios: | "success" | "noPostsFound" actors: { 'frontend': { from: { 'lambda': { in: | GetPosts__POSTS & { type: "POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "NO_POSTS_FOUND" } out: | GetPosts__GET_POSTS & { type: "GET_POSTS" } | GetPosts__GET_POSTS & { type: "GET_POSTS" } } } to: { 'lambda': { in: | GetPosts__GET_POSTS & { type: "GET_POSTS" } | GetPosts__GET_POSTS & { type: "GET_POSTS" } out: | GetPosts__POSTS & { type: "POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "NO_POSTS_FOUND" } } } } 'lambda': { from: { 'frontend': { in: | GetPosts__GET_POSTS & { type: "GET_POSTS" } | GetPosts__GET_POSTS & { type: "GET_POSTS" } out: | GetPosts__POSTS & { type: "POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "NO_POSTS_FOUND" } } } to: { 'frontend': { in: | GetPosts__POSTS & { type: "POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "NO_POSTS_FOUND" } out: | GetPosts__GET_POSTS & { type: "GET_POSTS" } | GetPosts__GET_POSTS & { type: "GET_POSTS" } } } } } } 'getFriendsOfUser': { scenarios: | "success" actors: { 'frontend': { from: { 'lambda': { in: | GetFriendsOfUser__FRIENDS_OF_USER & { type: "FRIENDS_OF_USER" } out: | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "GET_FRIENDS_OF_USER" } } } to: { 'lambda': { in: | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "GET_FRIENDS_OF_USER" } out: | GetFriendsOfUser__FRIENDS_OF_USER & { type: "FRIENDS_OF_USER" } } } } 'lambda': { from: { 'frontend': { in: | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "GET_FRIENDS_OF_USER" } out: | GetFriendsOfUser__FRIENDS_OF_USER & { type: "FRIENDS_OF_USER" } } } to: { 'frontend': { in: | GetFriendsOfUser__FRIENDS_OF_USER & { type: "FRIENDS_OF_USER" } out: | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "GET_FRIENDS_OF_USER" } } } } } } 'getComments': { scenarios: | "success" actors: { 'frontend': { from: { 'lambda': { in: | GetComments__COMMENTS & { type: "COMMENTS" } out: | GetComments__GET_COMMENTS & { type: "GET_COMMENTS" } } } to: { 'lambda': { in: | GetComments__GET_COMMENTS & { type: "GET_COMMENTS" } out: | GetComments__COMMENTS & { type: "COMMENTS" } } } } 'lambda': { from: { 'frontend': { in: | GetComments__GET_COMMENTS & { type: "GET_COMMENTS" } out: | GetComments__COMMENTS & { type: "COMMENTS" } } } to: { 'frontend': { in: | GetComments__COMMENTS & { type: "COMMENTS" } out: | GetComments__GET_COMMENTS & { type: "GET_COMMENTS" } } } } } } } export interface SextantActors { 'frontend': { from: { 'lambda': { in: | GetUsers__USERS & { type: "getUsers.USERS" } | GetPosts__POSTS & { type: "getPosts.POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "getPosts.NO_POSTS_FOUND" } | GetFriendsOfUser__FRIENDS_OF_USER & { type: "getFriendsOfUser.FRIENDS_OF_USER" } | GetComments__COMMENTS & { type: "getComments.COMMENTS" } out: | GetUsers__GET_USERS & { type: "getUsers.GET_USERS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "getFriendsOfUser.GET_FRIENDS_OF_USER" } | GetComments__GET_COMMENTS & { type: "getComments.GET_COMMENTS" } } } to: { 'lambda': { in: | GetUsers__GET_USERS & { type: "getUsers.GET_USERS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "getFriendsOfUser.GET_FRIENDS_OF_USER" } | GetComments__GET_COMMENTS & { type: "getComments.GET_COMMENTS" } out: | GetUsers__USERS & { type: "getUsers.USERS" } | GetPosts__POSTS & { type: "getPosts.POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "getPosts.NO_POSTS_FOUND" } | GetFriendsOfUser__FRIENDS_OF_USER & { type: "getFriendsOfUser.FRIENDS_OF_USER" } | GetComments__COMMENTS & { type: "getComments.COMMENTS" } } } }; 'lambda': { from: { 'frontend': { in: | GetUsers__GET_USERS & { type: "getUsers.GET_USERS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "getFriendsOfUser.GET_FRIENDS_OF_USER" } | GetComments__GET_COMMENTS & { type: "getComments.GET_COMMENTS" } out: | GetUsers__USERS & { type: "getUsers.USERS" } | GetPosts__POSTS & { type: "getPosts.POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "getPosts.NO_POSTS_FOUND" } | GetFriendsOfUser__FRIENDS_OF_USER & { type: "getFriendsOfUser.FRIENDS_OF_USER" } | GetComments__COMMENTS & { type: "getComments.COMMENTS" } } 'cognito': { in: | GetUsers__USER_FROM_COGNITO & { type: "getUsers.USER_FROM_COGNITO" } out: | GetUsers__GET_USER & { type: "getUsers.GET_USER" } } } to: { 'frontend': { in: | GetUsers__USERS & { type: "getUsers.USERS" } | GetPosts__POSTS & { type: "getPosts.POSTS" } | GetPosts__NO_POSTS_FOUND & { type: "getPosts.NO_POSTS_FOUND" } | GetFriendsOfUser__FRIENDS_OF_USER & { type: "getFriendsOfUser.FRIENDS_OF_USER" } | GetComments__COMMENTS & { type: "getComments.COMMENTS" } out: | GetUsers__GET_USERS & { type: "getUsers.GET_USERS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetPosts__GET_POSTS & { type: "getPosts.GET_POSTS" } | GetFriendsOfUser__GET_FRIENDS_OF_USER & { type: "getFriendsOfUser.GET_FRIENDS_OF_USER" } | GetComments__GET_COMMENTS & { type: "getComments.GET_COMMENTS" } } 'cognito': { in: | GetUsers__GET_USER & { type: "getUsers.GET_USER" } out: | GetUsers__USER_FROM_COGNITO & { type: "getUsers.USER_FROM_COGNITO" } } } }; 'cognito': { from: { 'lambda': { in: | GetUsers__GET_USER & { type: "getUsers.GET_USER" } out: | GetUsers__USER_FROM_COGNITO & { type: "getUsers.USER_FROM_COGNITO" } } } to: { 'lambda': { in: | GetUsers__USER_FROM_COGNITO & { type: "getUsers.USER_FROM_COGNITO" } out: | GetUsers__GET_USER & { type: "getUsers.GET_USER" } } } }; } export interface EventConfig { in: { type: string }; out: { type: string }; } type MaybePromise<T> = Promise<T> | T; type SextantPromise<TEventConfig extends EventConfig> = ( event: TEventConfig['in'], ) => MaybePromise< TEventConfig['out'] extends never ? void : TEventConfig['out'] >; /** * A handler type built by Sextant. * * Usage: * * ```ts * const handler: SextantHandler< * 'featureName', * 'fromThisActor', * 'toThisActor', * > = () => {}; * ``` */ export type SextantHandler< IFeature extends keyof SextantFeatures, IFrom extends keyof SextantFeatures[IFeature]["actors"] = any, // @ts-ignore ITarget extends keyof SextantFeatures[IFeature]["actors"][IFrom]["from"] = any > = SextantPromise< // @ts-ignore SextantFeatures[IFeature]["actors"][IFrom]["to"][ITarget] >; /** * An event type built by Sextant. * * Usage: * * ```ts * const event: SextantEvent<'featureName', 'fromThisActor', 'toThisActor'>; * const specificEvent: SextantEvent< * 'featureName', * 'fromThisActor', * 'toThisActor', * 'SPECIFIC_EVENT_TYPE' * >; * ``` */ export type SextantEvent< IFeature extends keyof SextantFeatures, IFrom extends keyof SextantFeatures[IFeature]["actors"] = any, // @ts-ignore ITarget extends keyof SextantFeatures[IFeature]["actors"][IFrom]["from"] = any, // @ts-ignore IType extends SextantFeatures[IFeature]["actors"][IFrom]["to"][ITarget]["in"]["type"] = any > = Extract< // @ts-ignore SextantFeatures[IFeature]["actors"][IFrom]["to"][ITarget]["in"], { type: IType } >; /** * Fetch all events from an environment to another environment, * across features */ export type SextantAllEventsToActor< IFrom extends keyof SextantActors, ITo extends keyof SextantActors[IFrom]['from'] = any, // @ts-ignore IType extends SextantActors[IFrom]['from'][ITo]['out']['type'] = any > = Extract< // @ts-ignore SextantActors[IFrom]['from'][ITo]['out'], { type: IType } >; export const sextantScenarios: { 'getUsers': [ 'success', ], 'getPosts': [ 'success', 'noPostsFound', ], 'getFriendsOfUser': [ 'success', ], 'getComments': [ 'success', ], };