dataverse-schema
Version:
A Schema library designed for Microsoft Dataverse to aid in Web API calls
1,046 lines (974 loc) • 125 kB
TypeScript
/**
* Generates a query expression for the "Above" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {string} value - The value to compare.
* @returns {string} The query expression for the "Above" operator.
*/
export declare function Above(name: string, value: string): string;
/**
* Generates a query expression for the "AboveOrEqual" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {string} value - The value to compare.
* @returns {string} The query expression for the "AboveOrEqual" operator.
*/
export declare function AboveOrEqual(name: string, value: string): string;
/**
* Activates a record in the specified Dataverse entity set by setting its 'statecode' to 0.
* Note that the actual attribute name for the state code might vary depending on the entity.
* This function assumes the standard 'statecode' attribute with a value of 0 representing the active state.
*
* @param entitySetName - The logical name of the entity set where the record is located (e.g., 'accounts', 'contacts', 'opportunities').
* @param id - The unique identifier of the record to activate.
* @returns A promise that resolves to the ID of the activated record upon successful activation.
*
* @example
* // Activate the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* activateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef')
* .then(activatedAccountId => console.log('Activated Account ID:', activatedAccountId))
* .catch(error => console.error('Error activating account:', error));
*
* @example
* // Activate the opportunity record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210'.
* activateRecord('opportunities', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210')
* .then(activatedOpportunityId => console.log('Activated Opportunity ID:', activatedOpportunityId))
* .catch(error => console.error('Error activating opportunity:', error));
*/
export declare function activateRecord(entitySetName: string, id: DataverseKey): Promise<string>;
/**
* Creates an OData aggregate expression.
*
* @param values An array of aggregation expressions (e.g., "price with average as avgPrice"). Empty or null values will be filtered out.
* @returns An OData aggregate expression string.
*
* @example
* // Aggregate with a single average:
* aggregate("price with average as avgPrice"); // returns "aggregate(price with average as avgPrice)"
*
* // Aggregate with multiple aggregations:
* aggregate("price with average as avgPrice", "quantity with sum as totalQuantity", "rating with average as avgRating");
* // returns "aggregate(price with average as avgPrice,quantity with sum as totalQuantity,rating with average as avgRating)"
*/
export declare function aggregate(...values: string[]): string;
/**
* Represents an alternate key for a Dataverse entity. An alternate key is used
* to uniquely identify a record instead of using its primary key (GUID).
* It can be a single key-value pair or a combination of multiple key-value pairs.
*/
export declare type AlternateKey = `${string}=${string}` | `${string}=${string},${string}=${string}`;
/**
* Combines multiple OData filter conditions with the "and" operator.
* Filters out any null or undefined conditions.
*
* @param conditions An array of OData filter conditions (strings), which can be null or undefined.
* @returns A string representing the combined conditions, or an empty string if no valid conditions are provided.
*
* @example
* // Example 1: Combining equals and greaterThan
* and(equals("name", "John"), greaterThan("age", 30));
* // returns "(name eq 'John' and age gt 30)"
*
* // Example 2: Combining with contains
* and(contains("description", "software"), equals("category", "application"));
* // returns "(contains(description,'software') and category eq 'application')"
*
* // Example 3: Handling null/undefined conditions
* and("name eq 'John'", null, greaterThan("age", 30));
* // returns "(name eq 'John' and age gt 30)"
*/
export declare function and(...conditions: (string | null | undefined)[]): string;
/**
* Associates an existing child record with a parent record through a single-valued navigation property in Dataverse.
*
* @param entitySetName - The logical name of the parent entity set (e.g., 'accounts').
* @param parentId - The unique identifier of the parent record.
* @param propertyName - The name of the single-valued navigation property on the parent entity that points to the child entity (e.g., 'primarycontactid', 'parentaccountid').
* @param childEntitySetName - The logical name of the child entity set (e.g., 'contacts', 'accounts').
* @param childId - The unique identifier of the child record to associate.
* @returns A promise that resolves to the ID of the associated child record upon successful association.
*
* @example
* // Associate the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210' as the primary contact of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* associateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'primarycontactid', 'contacts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210')
* .then(associatedContactId => console.log('Associated Contact ID:', associatedContactId))
* .catch(error => console.error('Error associating contact:', error));
*
* @example
* // Associate the account record with ID 'c7b6a5e4-f3d2-1a90-8765-43210fedcba9' as the parent account of the current account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* associateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'parentaccountid', 'accounts', 'c7b6a5e4-f3d2-1a90-8765-43210fedcba9')
* .then(associatedAccountId => console.log('Associated Account ID:', associatedAccountId))
* .catch(error => console.error('Error associating account:', error));
*/
export declare function associateRecord(entitySetName: string, parentId: DataverseKey, propertyName: string, childEntitySetName: string, childId: DataverseKey): Promise<DataverseKey>;
/**
* Associates a list of child records with a parent record through a collection-valued navigation property in Dataverse.
* This function adds associations for child records that are not currently associated and removes associations for child records that are currently associated but not in the provided list.
*
* @param entitySetName - The logical name of the parent entity set (e.g., 'accounts').
* @param parentId - The unique identifier of the parent record.
* @param propertyName - The name of the collection-valued navigation property on the parent entity that points to the child entities (e.g., 'contact_customer_accounts').
* @param childEntitySetName - The logical name of the child entity set (e.g., 'contacts').
* @param childPrimaryKeyName - The primary key attribute name of the child entity (e.g., 'contactid').
* @param childIds - An array of unique identifiers of the child records to associate with the parent record.
* @returns A promise that resolves to the array of child IDs provided in the input.
*
* @example
* // Associate a list of contact records with an account record.
* const contactIdsToAssociate = ['f9e8d7c6-b5a4-3210-fedc-ba9876543210', '12345678-90ab-cdef-1234-567890abcdef'];
* associateRecordToList('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'contact_customer_accounts', 'contacts', 'contactid', contactIdsToAssociate)
* .then(associatedContactIds => console.log('Associated Contact IDs:', associatedContactIds))
* .catch(error => console.error('Error associating contacts:', error));
*/
export declare function associateRecordToList(entitySetName: string, parentId: DataverseKey, propertyName: string, childEntitySetName: string, childPrimaryKeyName: string, childIds: DataverseKey[]): Promise<DataverseKey[]>;
export declare function attachEtag<T>(v: T): T;
/**
* Creates an OData aggregation expression for calculating the average of a property.
*
* @param name The name of the property to average.
* @param alias The alias for the resulting average value (defaults to the property name).
* @returns An OData aggregation expression string for average.
*
* @example
* average("price"); // returns "price with average as price"
* average("price", "avgPrice"); // returns "price with average as avgPrice"
*/
export declare function average(name: string, alias?: string): string;
/**
* Creates a data URL from a base64 encoded image string.
*
* @param base64 The base64 encoded image string.
* @returns A data URL representing the image.
*
* @example
* // Create a data URL from a base64 string:
* const base64String = "iVBORw0KGgoAAAANSUhEUg..."; // A long base64 string
* const imageUrl = base64ImageToURL(base64String);
* // returns "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..."
*/
export declare function base64ImageToURL(base64: string): string;
/**
* Generates a query expression for the "Between" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {string} value1 - The first value to compare.
* @param {string} value2 - The second value to compare.
* @returns {string} The query expression for the "Between" operator.
*/
export declare function Between(name: string, value1: string, value2: string): string;
/**
* A factory function to create a new BooleanProperty instance.
*
* @param name The name of the boolean property.
* @returns A new BooleanProperty instance.
*/
export declare function boolean(name: string): BooleanProperty;
/**
* Represents a boolean property within a dataverse schema.
* Extends the base Property class with a boolean type and a default value of false.
*/
export declare class BooleanProperty extends Schema<boolean> {
/**
* The kind of schema element for a boolean property, which is "value".
*/
kind: "value";
/**
* The type of the property, which is "boolean".
*/
type: "boolean";
/**
* Creates a new BooleanProperty instance.
*
* @param name The name of the boolean property.
*/
constructor(name: string);
}
/**
* A factory function to create a new CollectionProperty instance.
*
* @template TProperties An object defining the properties of the related records in the collection.
* @param name The name of the collection property.
* @param getTable A function that, when called, returns the Table definition for the related records.
* @returns A new CollectionProperty instance.
*/
export declare function collection<TProperties extends GenericProperties>(name: string, getTable: GetTable<Table<TProperties>>): CollectionProperty<TProperties>;
/**
* A factory function to create a new LookupsProperty instance.
*
* @param name The name of the collection of lookup properties.
* @param getTable A function that, when called, returns the Table definition for the related entity.
* @returns A new LookupsProperty instance.
*/
export declare function collectionIds(name: string, getTable: GetTable): CollectionIdsProperty;
/**
* Represents a collection of lookup (many-to-many navigation) properties within a dataverse schema.
* Extends the base Property class to handle arrays of references to other records by their GUIDs.
*/
export declare class CollectionIdsProperty extends Schema<GUID[]> {
#private;
/**
* The kind of schema element for a collection of lookups property, which is "navigation".
*/
kind: "navigation";
/**
* The type of the property, which is "lookups".
*/
type: "collectionIds";
/**
* Creates a new LookupsProperty instance.
*
* @param name The name of the collection of lookup properties.
* @param getTable A function that, when called, returns the Table definition for the related entity. This is used to avoid circular dependencies.
*/
constructor(name: string, getTable: GetTable);
get table(): Table<{
id: PrimaryKeyProperty;
}>;
/**
* Transforms an array of values received from Dataverse into an array of GUIDs of the related records.
* It iterates over the input array and extracts the value of the primary key property ('id') from each related record.
*
* @param value An array of raw data representing the related records from Dataverse.
* @returns An array of GUIDs of the related records.
*/
transformValueFromDataverse(value: any): GUID[];
getIssues(value: any, path?: PropertyKey[]): StandardSchemaV1.Issue[];
}
/**
* Represents a collection-valued navigation property within a dataverse schema.
* Extends the base Property class to handle arrays of related records.
*
* @template TProperties An object defining the properties of the related records in the collection.
*/
export declare class CollectionProperty<TProperties extends GenericProperties> extends Schema<Infer<TProperties>[]> {
#private;
kind: "navigation";
type: "collection";
/**
* Creates a new CollectionProperty instance.
*
* @param name The name of the collection property.
* @param getTable A function that, when called, returns the Table definition for the related records. This is used to avoid circular dependencies.
*/
constructor(name: string, getTable: GetTable<Table<TProperties>>);
get table(): Table<TProperties>;
/**
* Transforms an array of values received from Dataverse into an array of transformed related records.
* It iterates over the input array and uses the `transformValueFromDataverse` method of the related Table to transform each individual record.
*
* @param value An array of raw data representing the related records from Dataverse.
* @returns An array of transformed related records of type `Infer<TProperties>[]`.
*/
transformValueFromDataverse(value: any): Infer<TProperties>[];
getIssues(value: any, path?: PropertyKey[]): StandardSchemaV1.Issue[];
}
export declare type Config = {
url?: string;
headers: {
"OData-MaxVersion"?: string;
"OData-Version"?: string;
"Content-Type"?: string;
"If-None-Match"?: string;
Accept?: string;
Prefer?: string;
MSCRMCallerID?: string;
CallerObjectId?: string;
};
};
/**
* Generates a query expression for the "Contains" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {string} value - The value to check if it contains.
* @returns {string} The query expression for the "Contains" operator.
*/
export declare function Contains(name: string, value: string): string;
/**
* Creates an OData filter condition using the "contains" operator.
* Checks if a string property contains a specified substring.
*
* @param name The name of the string property to check.
* @param value The substring to search for.
* @returns A string representing the "contains" filter condition.
*
* @example
* contains("description", "software");
* // returns "contains(description,'software')"
*
* // Example: Combining with equals
* and(contains("description", "software"), equals("category", "application"));
* // returns "contains(description,'software') and (category eq 'application')"
*/
export declare function contains(name: string, value: Primitive): string;
/**
* Generates a query expression for the "ContainsValues" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {...string[]} values - The list of values to check if they are contained.
* @returns {string} The query expression for the "ContainsValues" operator.
*/
export declare function ContainsValues(name: string, ...values: string[]): string;
/**
* Creates an OData aggregation expression for counting the number of records.
*
* @param alias The alias for the resulting count value (defaults to "count").
* @returns An OData aggregation expression string for count.
*
* @example
* count(); // returns "$count as count"
* count("recordCount"); // returns "$count as recordCount"
*/
export declare function count(alias?: string): string;
/**
* Represents a Dataverse key, which can be either a GUID (primary key) or an AlternateKey.
*/
export declare type DataverseKey = GUID | AlternateKey;
/**
* Represents a Dataverse record, which is essentially a JavaScript object
* with properties corresponding to the columns/attributes in a Dataverse entity.
* The 'any' type is used here because the structure of a Dataverse record
* can vary significantly depending on the entity and the selected attributes.
*/
export declare type DataverseRecord = Record<string, Primitive>;
/**
* A factory function to create a new DateProperty instance.
*
* @param name The name of the date property.
* @returns A new DateProperty instance.
*/
export declare function date(name: string): DateProperty;
/**
* A factory function to create a new DateProperty instance.
*
* @param name The name of the date property.
* @returns A new DateProperty instance.
*/
export declare function dateOnly(name: string): DateOnlyProperty;
/**
* Represents a date property within a dataverse schema.
* Extends the base Property class with a Date or null type and a default value of null.
*/
export declare class DateOnlyProperty extends Schema<Date | null> {
/**
* The kind of schema element for a date property, which is "value".
*/
kind: "value";
/**
* The type of the property, which is "date".
*/
type: "dateOnly";
/**
* Creates a new DateProperty instance.
*
* @param name The name of the date property.
*/
constructor(name: string);
/**
* Transforms a value received from Dataverse into a Date object or null.
* If the value is null, it returns null. Otherwise, it creates a new Date object from the Dataverse value.
*
* @param value The value received from Dataverse.
* @returns A Date object or null.
*/
transformValueFromDataverse(value: any): Date | null;
transformValueToDataverse(value: any): string | null;
}
/**
* Represents a date property within a dataverse schema.
* Extends the base Property class with a Date or null type and a default value of null.
*/
export declare class DateProperty extends Schema<Date | null> {
/**
* The kind of schema element for a date property, which is "value".
*/
kind: "value";
/**
* The type of the property, which is "date".
*/
type: "date";
/**
* Creates a new DateProperty instance.
*
* @param name The name of the date property.
*/
constructor(name: string);
/**
* Transforms a value received from Dataverse into a Date object or null.
* If the value is null, it returns null. Otherwise, it creates a new Date object from the Dataverse value.
*
* @param value The value received from Dataverse.
* @returns A Date object or null.
*/
transformValueFromDataverse(value: any): Date | null;
}
/**
* Deactivates a record in the specified Dataverse entity set by setting its 'statecode' to 1.
* Note that the actual attribute name for the state code and the value for the inactive state might vary depending on the entity.
* This function assumes the standard 'statecode' attribute with a value of 1 representing the inactive state.
*
* @param entitySetName - The logical name of the entity set where the record is located (e.g., 'accounts', 'contacts', 'opportunities').
* @param id - The unique identifier of the record to deactivate.
* @returns A promise that resolves to the ID of the deactivated record upon successful deactivation.
*
* @example
* // Deactivate the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* deactivateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef')
* .then(deactivatedAccountId => console.log('Deactivated Account ID:', deactivatedAccountId))
* .catch(error => console.error('Error deactivating account:', error));
*
* @example
* // Deactivate the opportunity record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210'.
* deactivateRecord('opportunities', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210')
* .then(deactivatedOpportunityId => console.log('Deactivated Opportunity ID:', deactivatedOpportunityId))
* .catch(error => console.error('Error deactivating opportunity:', error));
*/
export declare function deactivateRecord(entitySetName: string, id: DataverseKey): Promise<string>;
/**
* Deletes the value of a single-valued property of an existing Dataverse record, setting it to null.
* This operation is only applicable to properties that support null values.
*
* @param entitySetName - The logical name of the entity set where the record is located (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record to update.
* @param propertyName - The name of the single-valued property to delete (e.g., 'description', 'address1_fax').
* @returns A promise that resolves to the ID of the updated record upon successful deletion of the property value.
*
* @example
* // Delete the value of the 'description' property of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* deletePropertyValue('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'description')
* .then(updatedAccountId => console.log('Updated Account ID:', updatedAccountId))
* .catch(error => console.error('Error deleting account description:', error));
*
* @example
* // Delete the value of the 'address1_fax' property of the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210'.
* deletePropertyValue('contacts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210', 'address1_fax')
* .then(updatedContactId => console.log('Updated Contact ID:', updatedContactId))
* .catch(error => console.error('Error deleting contact fax:', error));
*/
export declare function deletePropertyValue(entitySetName: string, id: DataverseKey, propertyName: string): Promise<DataverseKey>;
/**
* Deletes a record from the specified Dataverse entity set.
*
* @param entitySetName - The logical name of the entity set where the record will be deleted (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record to delete.
* @returns A promise that resolves to the ID of the deleted record upon successful deletion.
*
* @example
* // Delete the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* deleteRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef')
* .then(deletedAccountId => console.log('Deleted Account ID:', deletedAccountId))
* .catch(error => console.error('Error deleting account:', error));
*
* @example
* // Delete the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210'.
* deleteRecord('contacts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210')
* .then(deletedContactId => console.log('Deleted Contact ID:', deletedContactId))
* .catch(error => console.error('Error deleting contact:', error));
*/
export declare function deleteRecord(entitySetName: string, id: DataverseKey): Promise<DataverseKey>;
/**
* Dissociates (removes the association between) a child record from a parent record through a single-valued or collection-valued navigation property in Dataverse.
*
* @param entitySetName - The logical name of the parent entity set (e.g., 'accounts', 'opportunities').
* @param parentId - The unique identifier of the parent record.
* @param propertyName - The name of the navigation property on the parent entity that points to the child record(s) (e.g., 'primarycontactid', 'contact_customer_accounts').
* @param [childId] - The unique identifier of the child record to dissociate. This is required for collection-valued navigation properties and optional (or should be omitted) for single-valued navigation properties to clear the reference.
* @returns A promise that resolves to the ID of the dissociated child record (if provided) or the parent record ID if dissociating a single-valued property.
*
* @example
* // Dissociate the primary contact from the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef' (single-valued navigation property).
* disssociateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'primarycontactid')
* .then(parentId => console.log('Dissociated from Account ID:', parentId))
* .catch(error => console.error('Error dissociating primary contact:', error));
*
* @example
* // Dissociate the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210' from the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef' (collection-valued navigation property).
* disssociateRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'contact_customer_accounts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210')
* .then(childId => console.log('Dissociated Contact ID:', childId))
* .catch(error => console.error('Error dissociating contact:', error));
*/
export declare function disssociateRecord(entitySetName: string, parentId: DataverseKey, propertyName: string, childId?: DataverseKey): Promise<DataverseKey>;
/**
* Generates a query expression for the "DoesNotContainValues" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {...string[]} values - The list of values to check if they are not contained.
* @returns {string} The query expression for the "DoesNotContainValues" operator.
*/
export declare function DoesNotContainValues(name: string, ...values: string[]): string;
/**
* Creates a validator function that checks if a string is a valid email address.
* Uses a basic email validation regex.
*
* @returns A validator function that returns "Invalid email format" if the string is not a valid email address, otherwise undefined.
*
* @example
* // Create an email validator:
* const isEmail = email();
*
* // Validate an email address:
* isEmail("test@example.com"); // returns undefined (valid)
* isEmail("invalid"); // returns "Invalid email format" (invalid)
* isEmail("test@.com"); // returns "Invalid email format" (invalid)
*/
export declare function email(): Validator<string>;
/**
* Creates an OData filter condition using the "endswith" operator.
* Checks if a string property ends with a specified substring.
*
* @param name The name of the string property to check.
* @param value The substring to search for at the end of the property's value.
* @returns A string representing the "endswith" filter condition.
*
* @example
* endsWith("filename", ".txt"); // returns "endswith(filename,'.txt')"
*
* // Example: Combining with or
* or(endsWith("filename", ".txt"), endsWith("filename", ".pdf"));
* // returns "endswith(filename,'.txt') or endswith(filename,'.pdf')"
*/
export declare function endsWith(name: string, value: Primitive): string;
/**
* Generates a query expression for the "EqualBusinessId" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualBusinessId" operator.
*/
export declare function EqualBusinessId(name: string): string;
/**
* Generates a query expression for the "EqualRoleBusinessId" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualRoleBusinessId" operator.
*/
export declare function EqualRoleBusinessId(name: string): string;
/**
* Creates an OData filter condition using the "eq" (equals) operator.
* Checks if a property is equal to a specified value.
*
* @param name The name of the property to compare.
* @param value The value to compare the property against.
* @returns A string representing the "equals" filter condition.
*
* @example
* equals("age", 30); // returns "(age eq 30)"
* equals("name", "John"); // returns "(name eq 'John')"
*
* // Example: Combining with and
* and(equals("age", 30), equals("name", "John"));
* // returns "(age eq 30) and (name eq 'John')"
*/
export declare function equals(name: string, value: Primitive): string;
/**
* Generates a query expression for the "EqualUserId" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserId" operator.
*/
export declare function EqualUserId(name: string): string;
/**
* Generates a query expression for the "EqualUserLanguage" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserLanguage" operator.
*/
export declare function EqualUserLanguage(name: string): string;
/**
* Generates a query expression for the "EqualUserOrUserHierarchy" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserOrUserHierarchy" operator.
*/
export declare function EqualUserOrUserHierarchy(name: string): string;
/**
* Generates a query expression for the "EqualUserOrUserHierarchyAndTeams" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserOrUserHierarchyAndTeams" operator.
*/
export declare function EqualUserOrUserHierarchyAndTeams(name: string): string;
/**
* Generates a query expression for the "EqualUserOrUserTeams" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserOrUserTeams" operator.
*/
export declare function EqualUserOrUserTeams(name: string): string;
/**
* Generates a query expression for the "EqualUserTeams" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @returns {string} The query expression for the "EqualUserTeams" operator.
*/
export declare function EqualUserTeams(name: string): string;
export declare const Etag: unique symbol;
/**
* Creates an OData $expand expression.
*
* @param values A string or a record representing the properties to expand.
* If it is a string, it represents the navigation property name.
* If it is a record, the key is the navigation property name, and the value is a NestedQuery.
* @returns An OData $expand expression string.
*
* @example
* // Expand a single navigation property:
* $expand("orders");
* // returns "orders"
*
* // Expand a navigation property with nested select:
* $expand({ orders: { select: ["id", "orderDate"] } });
* // returns "orders($select=id,orderDate)"
*
* // Expand a navigation property with nested expand:
* $expand({
* customer: {
* select: ["id", "name"],
* expand: { address: { select: ["city", "street"] } }
* }
* });
* // returns "customer($select=id,name;$expand=address($select=city,street))"
*/
export declare function expand(values: string | Record<string, NestedQuery>): string;
export declare function fetchChoices(name: string): Promise<{
value: number;
color: string;
label: string;
description: string;
}[]>;
export declare function fetchXml(entitySetName: string, xml: string): Promise<Record<string, Primitive>[]>;
/**
* A factory function to create a new StringProperty instance.
*
* @param name The name of the string property.
* @returns A new StringProperty instance.
*/
export declare function formatted(name: string): FormattedProperty;
/**
* Represents a string property within a dataverse schema.
* Extends the base Property class with a string or null type and a default value of null.
*/
export declare class FormattedProperty extends Schema<string | null> {
/**
* The kind of schema element for a string property, which is "value".
*/
kind: "value";
/**
* The type of the property, which is "string".
*/
type: "formatted";
/**
* Creates a new StringProperty instance.
*
* @param name The name of the string property.
*/
constructor(name: string);
}
/**
* Represents a generic navigation property in a Dataverse entity. Navigation
* properties are used to define relationships between entities.
*/
export declare type GenericNavigationProperty = CollectionProperty<GenericProperties> | LookupProperty<GenericProperties> | LookupIdProperty | CollectionIdsProperty;
/**
* Represents a generic object of properties, where the keys are property names
* and the values are GenericProperty definitions. This is used to define the
* structure of a Dataverse entity.
*/
export declare type GenericProperties = Record<string, GenericProperty>;
/**
* Represents a generic property in a Dataverse entity. A property can be
* either a navigation property or a value property.
*/
export declare type GenericProperty = GenericNavigationProperty | GenericValueProperty;
/**
* Represents a generic value property in a Dataverse entity. Value properties
* store the actual data of an entity, such as strings, numbers, dates, etc.
*/
export declare type GenericValueProperty = PrimaryKeyProperty | StringProperty | NumberProperty | BooleanProperty | DateProperty | DateOnlyProperty | ImageProperty | ListProperty<string | number>;
/**
* Retrieves a single associated record from a navigation property of a Dataverse record.
*
* @param entitySetName - The logical name of the primary entity set (e.g., 'accounts').
* @param id - The unique identifier of the primary record.
* @param navigationPropertyName - The name of the navigation property to the related record (e.g., 'primarycontactid', 'parentaccountid').
* @param [query] - An optional OData query string to select fields or expand further related entities of the associated record (e.g., '$select=fullname,emailaddress1').
* @returns A promise that resolves to the retrieved associated Dataverse record object.
*
* @example
* // Retrieve the primary contact of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef',
* // selecting their full name and email address.
* getAssociatedRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'primarycontactid', '$select=fullname,emailaddress1')
* .then(contact => console.log('Primary Contact:', contact))
* .catch(error => console.error('Error retrieving primary contact:', error));
*
* @example
* // Retrieve the parent account of the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210',
* // selecting only the account name.
* getAssociatedRecord('contacts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210', 'parentaccountid', '$select=name')
* .then(parentAccount => console.log('Parent Account:', parentAccount))
* .catch(error => console.error('Error retrieving parent account:', error));
*/
export declare function getAssociatedRecord(entitySetName: string, id: DataverseKey, navigationPropertyName: string, query?: string): Promise<DataverseRecord | null>;
/**
* Retrieves multiple associated records from a navigation property of a Dataverse record.
*
* @param entitySetName - The logical name of the primary entity set (e.g., 'accounts').
* @param id - The unique identifier of the primary record.
* @param navigationPropertyName - The name of the collection-valued navigation property to the related records (e.g., 'contact_customer_accounts', 'opportunity_customer_contacts').
* @param [query=""] - An optional OData query string to filter, sort, select fields, and expand further related entities of the associated records (e.g., '$filter=startswith(fullname, \'B\')&$select=fullname,emailaddress1').
* @returns A promise that resolves to an array of associated Dataverse record objects.
*
* @example
* // Retrieve all contacts associated with the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* getAssociatedRecords('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'contact_customer_accounts')
* .then(contacts => console.log('Associated Contacts:', contacts))
* .catch(error => console.error('Error retrieving associated contacts:', error));
*
* @example
* // Retrieve the full name and email address of all active contacts associated with the account record
* // with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef', ordered by full name.
* getAssociatedRecords('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'contact_customer_accounts', '$filter=statecode eq 0&$select=fullname,emailaddress1&$orderby=fullname')
* .then(activeContacts => console.log('Active Associated Contacts:', activeContacts))
* .catch(error => console.error('Error retrieving active associated contacts:', error));
*/
export declare function getAssociatedRecords(entitySetName: string, id: DataverseKey, navigationPropertyName: string, query?: string): Promise<DataverseRecord[]>;
/**
* Constructs a URL to retrieve an image from Dataverse.
*
* @param entity The logical name of the entity the image belongs to.
* @param name The name of the image attribute.
* @param id The ID of the entity record.
* @returns A URL string to download the image.
*
* @example
* // Get the URL for a contact's profile image:
* const imageUrl = getImageUrl("contact", "entityimage", "12345");
* // returns "/Image/download.aspx?Entity=contact&Attribute=entityimage&Id=12345&Full=true"
*/
export declare function getImageUrl(entity: string, name: string, id: string): string;
/**
* Recursively retrieves all records from a paginated Dataverse response using the `@odata.nextLink`.
*
* @param result - An object containing the current page of Dataverse records and an optional `@odata.nextLink` property for the next page.
* @param result.value - An array of Dataverse record objects from the current page.
* @param [result["@odata.nextLink"]] - An optional URL to the next page of records.
* @returns A promise that resolves to a single array containing all retrieved Dataverse record objects across all pages.
*
* @example
* // Assuming 'initialRecords' is the result of an initial call to getRecords.
* getNextLink(initialRecords)
* .then(allRecords => console.log('All Records:', allRecords))
* .catch(error => console.error('Error retrieving all records:', error));
*/
export declare function getNextLink(result: {
"@odata.nextLink"?: string;
value: DataverseRecord[];
}): Promise<DataverseRecord[]>;
/**
* Retrieves the raw value of a single property of a Dataverse record.
* This is particularly useful for retrieving binary or other non-JSON formatted data.
*
* @param entitySetName - The logical name of the entity set (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record.
* @param propertyName - The name of the property to retrieve the raw value of (e.g., 'entityimage', 'documentbody').
* @returns A promise that resolves to the raw value of the property as a string.
*
* @example
* // Retrieve the raw value (as a string) of the 'entityimage' property
* // of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* getPropertyRawValue('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'entityimage')
* .then(imageData => {
* console.log('Raw Image Data (String):', imageData);
* // You might need to further process this string depending on the actual data type.
* })
* .catch(error => console.error('Error retrieving raw image:', error));
*
* @example
* // Retrieve the raw value (as a string) of the 'documentbody' property
* // of a custom entity record named 'mydocument' with ID 'fedcba98-7654-3210-0fed-cba987654321'.
* getPropertyRawValue('mydocument', 'fedcba98-7654-3210-0fed-cba987654321', 'documentbody')
* .then(documentData => {
* console.log('Raw Document Data (String):', documentData);
* // You might need to decode this string (e.g., from Base64) to get the actual document content.
* })
* .catch(error => console.error('Error retrieving raw document:', error));
*/
export declare function getPropertyRawValue(entitySetName: string, id: DataverseKey, propertyName: string): Promise<string>;
/**
* Constructs the URL to retrieve the raw value of a single property of a Dataverse record.
* This is particularly useful for retrieving binary or other non-JSON formatted data.
*
* @param entitySetName - The logical name of the entity set (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record.
* @param propertyName - The name of the property to retrieve the raw value of (e.g., 'entityimage', 'documentbody').
* @returns The URL that can be used to fetch the raw property value.
*
* @example
* // Get the URL to retrieve the raw value of the 'entityimage' property
* // of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'.
* const imageUrl = getPropertyRawValueURL('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'entityimage');
* console.log('Image URL:', imageUrl);
* // You can then use this URL with a fetch request to get the image data.
*
* @example
* // Get the URL to retrieve the raw value of the 'documentbody' property
* // of a custom entity record named 'mydocument' with ID 'fedcba98-7654-3210-0fed-cba987654321'.
* const documentUrl = getPropertyRawValueURL('mydocument', 'fedcba98-7654-3210-0fed-cba987654321', 'documentbody');
* console.log('Document URL:', documentUrl);
*/
export declare function getPropertyRawValueURL(entitySetName: string, id: DataverseKey, propertyName: string): string;
/**
* Retrieves the value of a single property of a Dataverse record.
*
* @param entitySetName - The logical name of the entity set (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record.
* @param propertyName - The name of the property to retrieve (e.g., 'name', 'emailaddress1').
* @returns A promise that resolves to the primitive value of the requested property (e.g., string, number, boolean).
* @example
* // Retrieve the 'name' property of the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'
* getPropertyValue('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', 'name')
* .then(accountName => console.log('Account Name:', accountName))
* .catch(error => console.error('Error retrieving account name:', error));
*
* @example
* // Retrieve the 'emailaddress1' property of the contact record with ID 'f9e8d7c6-b5a4-3210-fedc-ba9876543210'
* getPropertyValue('contacts', 'f9e8d7c6-b5a4-3210-fedc-ba9876543210', 'emailaddress1')
* .then(email => console.log('Contact Email:', email))
* .catch(error => console.error('Error retrieving contact email:', error));
*/
export declare function getPropertyValue(entitySetName: string, id: DataverseKey, propertyName: string): Promise<Primitive>;
/**
* Retrieves a single record from a Dataverse entity set.
*
* @param entitySetName - The logical name of the entity set (e.g., 'accounts', 'contacts').
* @param id - The unique identifier of the record to retrieve. This could be a string GUID.
* @param query An optional OData query string to filter or expand related entities (e.g., '$select=name,address1_city&$expand=primarycontactid($select=fullname)').
* @returns A promise that resolves to the retrieved Dataverse record object.
*
* @example
* // Retrieve the account record with ID 'a1b2c3d4-e5f6-7890-1234-567890abcdef'
* getRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef')
* .then(account => console.log(account))
* .catch(error => console.error('Error retrieving account:', error));
*
* @example
* // Retrieve the name and city of the account record with the specified ID,
* // and also expand the primary contact's full name.
* getRecord('accounts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', '$select=name,address1_city&$expand=primarycontactid($select=fullname)')
* .then(account => console.log(account))
* .catch(error => console.error('Error retrieving account with query:', error));
*/
export declare function getRecord(entitySetName: string, id: DataverseKey, query?: string): Promise<DataverseRecord | null>;
/**
* Retrieves multiple records from a Dataverse entity set.
*
* @param entitySetName - The logical name of the entity set (e.g., 'accounts', 'contacts').
* @param [query] - An optional OData query string to filter, sort, select fields, and expand related entities (e.g., '$filter=startswith(name, \'A\')&$orderby=name desc&$select=name,address1_city&$expand=primarycontactid($select=fullname)').
* @returns A promise that resolves to an array of Dataverse record objects.
*
* @example
* // Retrieve all account records.
* getRecords('accounts')
* .then(accounts => console.log('Accounts:', accounts))
* .catch(error => console.error('Error retrieving accounts:', error));
*
* @example
* // Retrieve the name and city of all active account records, ordered by name.
* getRecords('accounts', '$filter=statecode eq 0&$select=name,address1_city&$orderby=name')
* .then(activeAccounts => console.log('Active Accounts:', activeAccounts))
* .catch(error => console.error('Error retrieving active accounts:', error));
*/
export declare function getRecords(entitySetName: string, query?: string): Promise<DataverseRecord[]>;
export declare type GetTable<T = any> = () => T;
export declare const globalConfig: Config;
/**
* Creates an OData filter condition using the "gt" (greater than) operator.
* Checks if a property is greater than a specified value.
*
* @param name The name of the property to compare.
* @param value The value to compare the property against.
* @returns A string representing the "greater than" filter condition.
*
* @example
* greaterThan("price", 10.50); // returns "(price gt 10.50)"
*
* // Example: Combining with and
* and(greaterThan("price", 10), lessThan("price", 20));
* // returns "(price gt 10 and price lt 20)"
*/
export declare function greaterThan(name: string, value: Primitive): string;
/**
* Creates an OData filter condition using the "ge" (greater than or equal) operator.
* Checks if a property is greater than or equal to a specified value.
*
* @param name The name of the property to compare.
* @param value The value to compare the property against.
* @returns A string representing the "greater than or equal" filter condition.
*
* @example
* greaterThanOrEqual("quantity", 10); // returns "(quantity ge 10)"
*
* // Example: Combining with or
* or(greaterThanOrEqual("quantity", 10), equals("quantity", 5));
* // returns "(quantity ge 10) or (quantity eq 5)"
*/
export declare function greaterThanOrEqual(name: string, value: Primitive): string;
/**
* Creates an OData groupby expression.
*
* @param values An array of property names to group by. Empty or null values will be filtered out.
* @param aggregations Optional aggregation expressions to apply to the grouped data.
* @returns An OData groupby expression string.
*
* @example
* // Group by a single property:
* groupby(["category"]); // returns "groupby((category))"
*
* // Group by multiple properties:
* groupby(["category", "region", "year"]); // returns "groupby((category,region,year))"
*
* // Group by a single property with aggregation:
* groupby(["category"], "aggregate(price with average as avgPrice)");
* // returns "groupby((category),aggregate(price with average as avgPrice))"
*
* // Group by multiple properties with multiple aggregations:
* groupby(["category", "region"], aggregate(price with average as avgPrice, quantity with sum as totalQuantity));
* // returns "groupby((category,region),aggregate(price with average as avgPrice, quantity with sum as totalQuantity))"
*/
export declare function groupby(values: string[], aggregations?: string): string;
/**
* Represents a GUID (Globally Unique Identifier) string, a standard identifier
* used extensively in Dataverse (and Microsoft technologies in general).
* The format is a string with five sections separated by hyphens.
*/
export declare type GUID = `${string}-${string}-${string}-${string}-${string}`;
/**
* A factory function to create a new ImageProperty instance.
*
* @param name The name of the image property.
* @returns A new ImageProperty instance.
*/
export declare function image(name: string): ImageProperty;
/**
* Represents an image property within a dataverse schema.
* Extends the base Property class with a string or null type to store the image data (e.g., as a base64 encoded string) and a default value of null.
*/
export declare class ImageProperty extends Schema<string | null> {
/**
* The kind of schema element for an image property, which is "value".
*/
kind: "value";
/**
* The type of the property, which is "image".
*/
type: "image";
/**
* Creates a new ImageProperty instance.
*
* @param name The name of the image property.
*/
constructor(name: string);
}
/**
* Generates a query expression for the "In" operator in Microsoft Dynamics CRM.
*
* @param {string} name - The name of the property.
* @param {...string[]} values - The list of values to check i