cbcore-ts
Version:
CBCore is a library to build web applications using pure Typescript.
163 lines (162 loc) • 5.69 kB
TypeScript
export type CBReferenceID = string;
export interface CBLanguageItem {
value: string;
languageKey: string;
itemKey: string;
}
export interface LanguagesData {
[key: string]: {
[key: string]: string;
};
}
export interface CBFinancialAmount {
amount: number;
currency: string;
}
export interface CBLocalizedTextObject {
[key: string]: string;
}
export interface CBDropdownData<T> {
_id: CBReferenceID;
name?: CBLocalizedTextObject;
dropdownCode: string;
data: CBDropdownDataItem<T>[];
}
export interface CBDropdownDataItem<T> {
_id: CBReferenceID;
title: CBLocalizedTextObject;
rowsData?: CBDropdownDataItem<T>[];
isADropdownDataSection: boolean;
isADropdownDataRow: boolean;
attachedObject: T;
itemCode: string;
dropdownCode: string;
}
export interface CBFileAccessor {
fileData: CBFileData;
createdAt: number;
}
export interface CBFileData {
_id: string;
name: string;
dataURL: string;
type: string;
isLimitedAccess?: boolean;
accessibleToUsers?: CBUserProfilePublic[];
}
export declare enum CBAuthenticationSource {
google = 10,
facebook = 11,
emailAccessLink = 200,
password = 220,
inquiryAccessLink = 500
}
export interface CBCoreInitializer {
languageValues: LanguagesData;
defaultLanguageKey: string;
}
export interface CBLoginKey {
key: string;
accessToken: string;
storeAccessTokenInClient: boolean;
authenticationSource: CBAuthenticationSource;
userID: CBReferenceID;
isValid: boolean;
loginDate?: Date;
logoutDate?: Date;
createdAt: Date;
updatedAt: Date;
}
export interface CBUserPassword {
passwordHash: string;
userID: CBReferenceID;
isValid: boolean;
createdAt: Date;
updatedAt: Date;
}
export interface CBAdministratorRightsDescriptor {
userProfile: CBUserProfile;
}
export interface CBSubscription {
_id: CBReferenceID;
startDate: Date;
endDate?: Date;
isIndefinite: boolean;
subscriptionKind: number;
createdAt: Date;
updatedAt: Date;
}
export type CBUserProfilePublic = any;
export type CBUserProfile = any;
export interface SocketClientInterface {
[x: string]: SocketClientFunction<any, any>;
}
export interface SocketClientResult<ResultType> {
responseMessage: any;
result: ResultType;
errorResult: any;
respondWithMessage: CBSocketMessageSendResponseFunction;
}
export type SocketClientFunction<MessageType, ResultType> = (messageData: MessageType, completionPolicy?: string, isUserBound?: boolean) => Promise<SocketClientResult<ResultType>>;
export type SocketClientNoMessageFunction<ResultType> = (messageData?: null, completionPolicy?: string, isUserBound?: boolean) => Promise<SocketClientResult<ResultType>>;
export interface CBSocketMultipleMessageObject<MessageDataType = any> {
key: string;
message: CBSocketMessage<MessageDataType>;
}
export interface CBSocketMessage<MessageDataType = any> {
identifier: string;
inResponseToIdentifier?: string;
keepWaitingForResponses?: boolean;
completionPolicy: string;
messageData: MessageDataType;
storedResponseHash?: string;
messageDataHash?: string;
canBeStoredAsResponse?: boolean;
useStoredResponse?: boolean;
responseValidityDuration?: number;
}
export interface CBSocketMultipleMessage extends CBSocketMessage<CBSocketMultipleMessageObject[]> {
shouldGroupResponses: boolean;
}
export type CBSocketMessageSendResponseFunctionBase<ResponseMessageType> = (responseMessage: ResponseMessageType, completion?: CBSocketMessageCompletionFunction) => Promise<string>;
export type CBSocketMessageCompletionFunction = (responseMessage: any, respondWithMessage: CBSocketMessageSendResponseFunction) => void;
export type CBSocketMessageHandlerFunction<ResponseMessageType = any> = (message: any, respondWithMessage: CBSocketMessageSendResponseFunction<ResponseMessageType>) => void;
export type CBSocketMultipleMessagecompletionFunction = (responseMessages: any[], callcompletionFunctions: () => void) => void;
export interface CBSocketMessageSendResponseFunction<ResponseMessageType = any> extends CBSocketMessageSendResponseFunctionBase<ResponseMessageType> {
respondingToMainResponse: boolean;
excludeMessageFromAutomaticConnectionEvents: () => void;
deferResponse: () => void;
setResponseValidityDuration(duration: number): void;
useStoredResponseWithErrorResponse(): void;
sendErrorResponse(message?: any, completion?: CBSocketMessageCompletionFunction): void;
sendIntermediateResponse(updateMessage: any, completion?: CBSocketMessageCompletionFunction): void;
confirmStoredResponseHash(responseHash: string, completion?: CBSocketMessageCompletionFunction): boolean;
isValid: boolean;
cancelHandling(): void;
message: CBSocketMessage;
key: string;
}
export interface CBSocketHandshakeInitMessage {
accessToken?: string;
userID: CBReferenceID;
loginKey?: string;
inquiryAccessKey?: string;
instanceIdentifier: string;
}
export interface CBSocketHandshakeResponseMessage {
accepted: boolean;
userProfile?: CBUserProfile;
}
export type TypeWithoutKey<Type, Key> = Pick<Type, Exclude<keyof Type, Key>>;
export type TypeWithoutID<Type> = TypeWithoutKey<Type, "_id">;
export type Diff<T extends keyof any, U extends keyof any> = ({
[P in T]: P;
} & {
[P in U]: never;
} & {
[x: string]: never;
})[T];
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
export type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
};