UNPKG

@sassoftware/vi-api

Version:
692 lines (691 loc) 25 kB
import { SearchRepresentation } from "../svi-sand"; import { Comment, DocumentAndLink, Relationship, RelationshipDTO, StoredObjectFieldDTO } from "../svi-datahub"; import { FileOperation } from "../file/file-api"; import { PageModel, PageModelData } from "../page-model/page-model-api"; import { ClientSheet, Sheet } from "../sheet/sheet-api"; import { PageViewerApi } from "../component/bindings"; import { PageDataChange, PageModeChange } from "../control"; export interface ISearchQuery { text?: string; additionalModes?: string[]; assistedSearchEnabled?: boolean; assistedSearchPrompt?: string; generatedTextQuery?: SearchRepresentation; } export type UnknownRecord = Record<string, unknown>; export type PageModelOrData = PageModel | PageModelData | null; export type SearchAndCreateNewPageModel = { model?: PageModelOrData; }; export interface ObjectIdentifier { id: string; type: string; } export interface ObjectAccessRules { canReadObject: Promise<boolean>; canUpdateObject: Promise<boolean>; canDeleteObject: Promise<boolean>; } export interface FormatObjectFieldsOptions { skipFormatReferenceData?: boolean; skipFormatUserGroups?: boolean; skipFormatBooleans?: boolean; /** * A function that will be the last thing called in order to format the object's field values. * @param fieldValue the current value of the field being formatted. * @param fieldName the name of the field currently being formatted. * @param objectFields all of the available fields in the object. * @param fieldMetadata the current field's metadata. */ formatCallback?: (fieldValue: string | number | Date | PageData[], fieldName: string, objectFields: FieldValues, fieldMetadata: StoredObjectFieldDTO) => void; } export interface UpdateObjectOptions { fileOperations?: FileOperation[]; isExternalObject?: boolean; sheets?: ClientSheet[]; } export interface CreateObjectOptions { comments?: Comment[]; fileOperations?: FileOperation[]; sheets?: ClientSheet[]; } /** * This API provides the functionality related to objects within SAS Visual Investigator. * * Accessed from the window at `window.sas.vi.object`. * * @example window.sas.vi.object.getObjectAccessRules(objectType, objectId); * @category API */ export interface ObjectApi { /** * @method * @description Gets the object access rules for an object: * The three methods that return booleans based on specified object are: * * canReadObject, * canUpdateObject, * and canDeleteObject. * * @param objectType {string} Object type. * @param objectId {string} Object ID. * @return Object with three boolean methods which provide boolean data on a specified object. */ getObjectAccessRules(objectType: string, objectId: string): ObjectAccessRules; /** * @method * @description Gets the specified object. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @param [includeDisplayLabel = true] {boolean} Checks whether or not to return the object with a display label. * @param [includeChildObjects = false] {boolean} Checks whether or not to return the child objects associated with this object. * @return The specified object. */ getObject(objectType: string, objectId: string, includeDisplayLabel?: boolean, includeChildObjects?: boolean): Promise<VIObject>; /** * @method * @description Gets the child objects of an object. * @param objectType {string} Object type. * @param objectId {string} Gets the child objects relating to the object ID. * @param childObjectType {string} Child object type. * @param [limit = 25] {number} Maximum number of child objects to be returned. * @return A Promise that resolves to an array of objects, that are child objects of the specified object. */ getChildObjects(objectType: string, objectId: string, childObjectType: string, limit?: number): Promise<VIObject[]>; /** * @method * @description Updates an existing object with the provided data. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @param objectTypeId {number} Object type ID. * @param objectTypeVersion {number} Object type version. * @param fieldValues {FieldValues} Field values of the object. * @param [options] {UpdateObjectOptions} Optional extra parameters. * @return A Promise that resolves to the updated object when the object been successfully updated. */ updateObject(objectType: string, objectId: string, objectTypeId: number, objectTypeVersion: number, fieldValues: FieldValues, options?: UpdateObjectOptions): Promise<VIObject>; /** * @method * @description Updates an existing object with the provided data. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @param objectTypeId {number} Object type ID. * @param objectTypeVersion {number} Object type version. * @param originalFieldValues {FieldValues} Field values before the object was edited * @param newFieldValues {FieldValues} Field values after the object was edited * @param objectVersion {number} Object Version * @param [options] {UpdateObjectOptions} Optional extra parameters. * @return A Promise that resolves to the updated object when the object has been successfully updated. */ patchObject(objectType: string, objectId: string, objectTypeId: number, objectTypeVersion: number, originalFieldValues: FieldValues, newFieldValues: FieldValues, objectVersion: number, options?: UpdateObjectOptions): Promise<VIObject>; /** * @method * @description Deletes an object. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @return A Promise that resolves to void when the specified object is successfully deleted. */ deleteObject(objectType: string, objectId: string): Promise<void>; /** * @method * @description Creates an object. * @param objectType {string} Object type. * @param objectTypeId {number} Object type ID. * @param fieldValues {FieldValues} Field values of the object. * @param [options] {CreateObjectOptions} Optional extra parameters. * @return A Promise that resolves to the created object when the object has successfully been created. */ createObject(objectType: string, objectTypeId: number, fieldValues: FieldValues, options?: CreateObjectOptions): Promise<VIObject>; /** * @method * @description Gets relationship via the relationship ID. * @param relationshipId {string} Relationship ID. * @return A Promise that resolves to a relationship. */ getObjectRelationship(relationshipId: string): Promise<ObjectRelationship>; /** * @method * @description Updates an existing relationship in SAS Visual Investigator. * @param relationshipId {string} Relationship ID. * @param payload {unknown} HTTP request content. * @return A Promise that resolves to a relationship. */ updateObjectRelationship(relationshipId: string, payload: unknown): Promise<ObjectRelationship>; /** * @method * @description Updates an existing relationship in SAS Visual Investigator. * @param relationshipId {string} Relationship ID. * @param originalFieldValues {FieldValues} Field values before the relationship was edited * @param newFieldValues {FieldValues} Field values after the relationship was edited * @return A Promise that resolves to a relationship. */ patchObjectRelationship(relationshipId: string, originalFieldValues: FieldValues, newFieldValues: FieldValues): Promise<ObjectRelationship>; /** * @method * @description Deletes relationship with the specified ID. * @param relationshipId {string} Relationship ID. * @return A Promise that resolves to void when the object is successfully deleted. */ deleteObjectRelationship(relationshipId: string): Promise<void>; /** * @method * @description Creates a relationship between two objects. * @param from {LinkObject} Object that relationship is from. * @param to {LinkObject} Object that relationship is to. * @param relationship {ObjectRelationship} The relationship. * @return A Promise that resolves to an object. */ relateObject(from: LinkObject, to: LinkObject, relationship: ObjectRelationship): Promise<ObjectRelationship>; /** * @method * @description Gets object summary label. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @return Summary label as a String. */ getObjectSummaryLabel(objectType: string, objectId: string): Promise<string>; /** * @method * @description Creates a new object and relates it with an existing one. * @param from {LinkObject} Existing Object that the relationship is from. * @param to {NewLinkObject} New Object to be created and related to. * @param relationship {ObjectRelationship} The relationship. * @param [includeCreatedObject = false] {boolean} If true, returns both the documentLink and created document details. * @return A Promise that resolves to the documentLink, or full response containing both documentLink and document. */ createAndRelateObject(from: LinkObject, to: NewLinkObject, relationship: ObjectRelationship, includeCreatedObject?: false): Promise<ObjectRelationship>; createAndRelateObject(from: LinkObject, to: NewLinkObject, relationship: ObjectRelationship, includeCreatedObject: true): Promise<DocumentAndLink>; createAndRelateObject(from: LinkObject, to: NewLinkObject, relationship: ObjectRelationship, includeCreatedObject?: boolean): Promise<ObjectRelationship | DocumentAndLink>; /** * @method * @description Processes an array of objects and formats them for display. * @param objects {VIObject[]} Array of objects. * @param objectType {string} Type of the objects in the array. * @param [options] {FormatObjectFieldsOptions} Optional parameters to control the formatting. By default, nothing is skipped and there is no formatCallback. * @return A Promise that resolves to the formatted array of objects. */ formatObjectFieldsForDisplay(objects: VIObject[], objectType: string, options?: FormatObjectFieldsOptions): Promise<VIObject[]>; /** * @method * @description Uploads an attachment. * @param attachmentModel {AttachmentModel} Attachment model. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @return A Promise that resolves to a HttpResponse with a FileAssociationResponse as the data. */ uploadAttachment(attachmentModel: AttachmentModel, objectType: string, objectId: string): Promise<FileAssociationResponse>; /** * @method * @description Deletes the specified attachment of the associated object. * @param objectType {string} Object type. * @param objectId {string} Object ID. * @param attachmentId {string} Attachment ID. * @return A Promise that resolves to an empty HttpResponse when the attachment is successfully deleted. */ deleteAttachment(objectType: string, objectId: string, attachmentId: string): Promise<void>; /** * @method * @description Gets an attachment of the associated object. * @param objectId {string} Object ID. * @param objectType {string} Object type. * @param attachmentId {string} Attachment ID. * @return A Promise that resolves to a HttpResponse with a FileAssociationResponse as the data. */ getAttachment(objectType: string, objectId: string, attachmentId: string): Promise<FileAssociationResponse>; /** * @method * @description Validates the fields, controls, and file categories of a child object. * @param {PageModel} model Page model. * @param {StoredObjectMetadata} childObject Child object metadata. * @return An observable that resolves to an array of validation results. */ validate(model: PageModel, childObject: StoredObjectMetadata): Promise<ValidationResult[]>; /** * @method * @description Launches a wizard allowing users to create an object/relationship. * The relationship wizard is determined by the relateToParentLabel or relateToParentName defined in the wizardValues parameter. * @param wizardValues {CreateDialogModel} Object containing entity and relationship data. * @returns A Promise that resolves when the dialog box is closed. */ openCreateAndLinkDialog(wizardValues: CreateDialogModel): Promise<CreateDialogModel>; } export interface PageData { fieldValues: FieldValues; id: string; displayLabel?: string; } export interface FieldValues { [property: string]: string | number | Date | PageData[]; } export interface ObjectSheetSettings { id: string; type: string; title: string; allowWorksheets: boolean; allowWorksheetCreation: boolean; allowNotesheets: boolean; allowNotesheetCreation: boolean; } export interface VIObject { fieldValues: FieldValues; comments?: Comment[]; fileOperations?: FileOperation[]; createdAt: string; displayLabel?: string; lastUpdatedAt: string; objectTypeId: number; objectTypeName: string; sheets?: Sheet[]; id: string; title?: string; } export type LinkObject = Pick<VIObject, "id" | "objectTypeName">; export type NewLinkObject = Pick<VIObject, "objectTypeName" | "fieldValues" | "fileOperations">; export interface ValidationResult { isValid: boolean; message?: string; } export interface PageAction { attrs: { actionId: number; actionName: string; attributes: { [property: string]: unknown; displayName: string; disabled: boolean; }; controlId?: number; displayName: string; }; } export interface PageActions { items?: PageAction[]; } export interface ControlContainer { childNodes?: ChildNode[]; } export interface PageTemplateScreen extends ControlContainer { id: string; name: string; locked?: boolean; } export interface PageTemplate { errors?: boolean; errorDetails?: Error; showTabs: boolean; id?: number; screens: PageTemplateScreen[]; } export interface FieldRestriction { maxLength?: number; required?: boolean; fieldDataType?: string; allowMultipleFiles?: boolean; constrainingListName?: string; cascadingReferenceDataFilterByCode?: string; cascadingReferenceDataFilterByField?: string; } export interface FieldRestrictions { [property: string]: FieldRestriction; } export interface ObjectFieldRestrictions { [property: string]: FieldRestrictions; } export interface TypeAttributes { [property: string]: unknown; } export interface NodeStates { readOnly?: boolean; required?: boolean; hidden?: boolean; } interface GlobalNodeStates extends NodeStates { conditions?: unknown[]; } export interface NodeAttributes extends TypeAttributes { global?: { state?: GlobalNodeStates; groupRestrictions?: Array<{ id: string; name: string; }>; }; } export declare enum ActionState { Disabled = "disabled", Hidden = "hidden" } export interface ChildNodeAttrs { attributes?: { disabled: boolean; state?: ActionState; }; id: string; category: string; type: string; states?: NodeStates; } export interface ChildNode extends ControlContainer { id: string; _fullScreen?: boolean; attributes?: NodeAttributes; typeAttributes: TypeAttributes; inheritedAttributes?: TypeAttributes; attrs: ChildNodeAttrs; } export declare enum ConditionReferenceType { TemplateControl = "TEMPLATE_CONTROL", Condition = "CONDITION", RequiredField = "REQUIRED_FIELD", ReadOnlyField = "READ_ONLY_FIELD", NldStyling = "NLD_STYLING" } export interface ConditionReference { association: string; type: ConditionReferenceType; } export declare enum ConditionFactType { Field = "FIELD", Condition = "CONDITION_REFERENCE" } export interface ConditionFact { factType: ConditionFactType; factPlaceholder: string; factValue: string; } export interface Condition { type: string; parameters: Array<string | number | boolean | Condition>; isComplete?: boolean; } export interface StoredObjectField { id: number; label: string; name: string; columnName: string; dataType: string; length?: number; required: boolean; primaryKeyField: boolean; unique: boolean; autoGenerated: boolean; systemReserved: boolean; displayIndex: number; version: number; primaryKeySeqNo?: number; readOnly: boolean; indexedForSearch: boolean; showTimeZone: boolean; ownerName: string; constrainingListName?: string; cascadingReferenceDataFilterByCode?: string; cascadingReferenceDataFilterByField?: string; } export interface FieldOperand { type: string; fieldName: string; objectName: string; } export interface BooleanExpression { type: string; leftOperand?: unknown; operator: string; rightOperand: unknown; } export interface ConditionalExpression extends BooleanExpression { type: string; leftOperand: unknown; operator: string; rightOperands: unknown[]; } export interface ObjectIcon { id: number; name: string; imageType: string; imageLocation: string; version: number; } export interface StoredObjectFileCategory { name: string; displayName: string; allowMultiple?: boolean; required?: boolean; documentLockRequired?: boolean; } export interface StoredObjectMetadata { id: number; label: string; description: string; name: string; tableName: string; historyEnabled: boolean; version: number; lastUpdatedAtTimeFieldName: string; createdAtTimeFieldName: string; displayTextFields?: DisplayTextFields[]; dataStoreAssignedTimeZone: string; type: string; markerColor: string; nodeShape: string; nodeColor: string; borderColor: string; borderWidth: number; indexedForSearch: boolean; attachmentsIndexedForSearch: boolean; fields?: StoredObjectField[]; relationshipsFrom?: Relationship[]; defaultRegularIcon: ObjectIcon; requireSearchBeforeCreate: boolean; fileCategories?: StoredObjectFileCategory[]; } export interface ObjectRelationship { relationshipTypeName?: string; relationshipTypeLabel?: string; id?: string; createdAt?: Date; lastUpdatedAt?: Date; validFrom?: Date; validTo?: Date; displayLabel?: string; fromObjectTypeName?: string; fromObjectTypeVersion?: number; fromObjectId?: string; fromObjectDisplayLabel?: string; toObjectTypeName?: string; toObjectTypeVersion?: number; toObjectId?: string; toObjectDisplayLabel?: string; fieldValues?: UnknownRecord; qualifiedTypeName?: string; } export interface ObjectRelationshipMultiple extends ObjectRelationship { fromId?: string; fromEntityType?: string; toId?: string; toEntityType?: string; operation?: string; } export interface AttachmentRow { description?: string; location: string; id: string; uploadedBy?: string; name: string; size: number; type: string; } export interface AttachmentModel { id: string; name: string; type?: string; description?: string; location: string; uploadedBy?: string; size?: number; selectedFile: AttachmentRow; } export interface RestRepresentationsLink { method?: string; rel?: string; href?: string; uri?: string; type?: string; responseType?: string; itemType?: string; responseItemType?: string; title?: string; } export interface FileAssociationResponse { version?: number; id?: string; name?: string; category?: string; location?: string; type?: string; size?: number; description?: string; properties?: UnknownRecord; uploadedAt?: Date; uploadedBy?: string; extractedContent?: string; displayOrder?: number; links?: RestRepresentationsLink[]; } export interface DisplayTextFields { name: string; displayIndex: number; } export declare enum SearchAndCreateStep { Search = "search", SearchResults = "searchResults", Entity = "entity", Relationship = "relationship" } export interface SearchAndCreatePanelContext { [SearchAndCreateStep.Search]: { doSearch: (query: string, additionalModes?: string[]) => void; updateAssistedSearchEnabled: (assistedSearchEnabled: boolean) => void; getQuery: () => ISearchQuery; updateQuery: (query: string) => void; }; [SearchAndCreateStep.SearchResults]: { getQuery: () => ISearchQuery; updateQuery: (query: string) => void; updateSelection: (results: Array<{ id: string; type: string; }>) => void; }; [SearchAndCreateStep.Entity]: { setPageViewerApi(api: PageViewerApi): void; onPageChange(change?: PageDataChange | PageModeChange): void; newPageModel: SearchAndCreateNewPageModel; selectedItems: Array<{ id?: string; type?: string; title?: string; }> | null | undefined; }; [SearchAndCreateStep.Relationship]: { updateLinkReason: (linkReason: Relationship) => void; onPageChange(change?: PageDataChange | PageModeChange): void; setPageViewerApi(api: PageViewerApi): void; newPageModel: SearchAndCreateNewPageModel; selectedItems: Array<{ id?: string; type?: string; title?: string; }> | null | undefined; }; } export interface SearchAndCreateFooterContext { query?: ISearchQuery; selectedItems?: Array<{ id?: string; type?: string; title?: string; }> | null; linkReason?: Relationship; newPageModel?: SearchAndCreateNewPageModel; relationshipValues?: UnknownRecord; relationshipInfoStepNeeded?: boolean; doSearch: (queryText?: string) => void; updateAssistedSearchEnabled?: (assistedSearchEnabled: boolean) => void; commit: () => void; relateToSelected: () => void; relateToNew: () => void; close: (result?: unknown) => void; } interface BaseButton { label: string; primary?: boolean; disabled?: boolean; } export type SearchAndCreateDialogButton = (BaseButton & { onClick: () => void | Promise<void>; }) | (BaseButton & { items: Array<{ text: string; click: () => void; }>; }); export interface CustomSearchAndCreateStep<Step extends SearchAndCreateStep> { panel?: { render: (container: HTMLDivElement, context: SearchAndCreatePanelContext[Step]) => void | (() => void); }; footer?: { getButtons: (context: SearchAndCreateFooterContext) => SearchAndCreateDialogButton[]; }; } export type CustomSearchAndCreateSteps = { [Step in SearchAndCreateStep]?: CustomSearchAndCreateStep<Step>; }; export interface SearchOrCreateAndLinkDialogBase<T> { entityName: string; entityLabel: string; entityNames?: string[]; entityLabels?: string[]; onClose?: (result?: T) => Promise<boolean>; /** * Values returned on the close of the dialog box. May be undefined when dialog box is cancelled. */ result?: T; multipleSearchChoice?: boolean; showPageViewer?: boolean; customSteps?: CustomSearchAndCreateSteps; customResult?: unknown; } export interface CreateRelationshipDialogModel<T> extends SearchOrCreateAndLinkDialogBase<T> { relateToParentName: string; relateToParentLabel: string; linkReasons?: Relationship[]; } export type CreateDialogModel = CreateRelationshipDialogModel<CreateDialogResponse>; export interface CreateDialogResponse { relateToModel?: CreateRelateToModel; } export interface CreateRelationshipDialogResultModel { linkReason?: Relationship; } export interface CreateRelateToModel extends CreateRelationshipDialogResultModel { newPageModel?: { model: PageModel; }; } export interface IRelationshipWithLabel extends RelationshipDTO { relationshipLabel: string; } export type APISelectedItem = ObjectIdentifier & { title?: string; uniqueKey?: string; typeLabel?: string; }; export interface RelationshipInformation { relationshipTypeId?: number; relationshipValues?: UnknownRecord; selectedItemTitle?: string; requiredFieldsStatus?: unknown; entityIconClass?: string; entityType?: string; } export {};