Socket
Socket
Sign inDemoInstall

@memberjunction/core

Package Overview
Dependencies
Maintainers
4
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@memberjunction/core - npm Package Compare versions

Comparing version 1.0.9 to 1.0.11

76

dist/generic/baseEntity.d.ts

@@ -5,2 +5,6 @@ import { EntityFieldInfo, EntityInfo, EntityFieldTSType, EntityPermissionType, RecordChange, ValidationResult, EntityRelationshipInfo, PrimaryKeyValue } from './entityInfo';

import { TransactionGroupBase } from './transactionGroup';
/**
* Represents a field in an entity. This class is used to store the value of the field, dirty state, as well as other run-time information about the field. The class encapsulates the underlying field metadata and exposes some of the more commonly
* used properties from the entity field metadata.
*/
export declare class EntityField {

@@ -21,11 +25,37 @@ private _entityFieldInfo;

get IsUnique(): boolean;
/**
* Returns the current value of the field.
*/
get Value(): any;
get ReadOnly(): boolean;
get EntityFieldInfo(): EntityFieldInfo;
/**
* Sets the value of the field. If the field is read only, nothing happens. If the field is not read only, the value is set and the internal representation of the dirty flag is flipped if the value is different from the old value.
*/
set Value(value: any);
/**
* Returns true if the field is dirty, false otherwise. A field is considered dirty if the value is different from the old value. If the field is read only, it is never dirty.
*/
get Dirty(): boolean;
/**
* Convenience method to format the value of the field. This method calls the static method on EntityFieldInfo to do the actual formatting.
* @param decimals
* @param currency
* @returns
*/
FormatValue(decimals?: number, currency?: string): string;
/**
* Validates the current value of the field. If the field is read only, or if the field is marked to skip validation, nothing happens.
* If the field is not read only, and the field is not marked to skip validation, the value is checked against the validation rules defined in the metadata for the field.
* @returns
*/
Validate(): ValidationResult;
constructor(fieldInfo: EntityFieldInfo, Value?: any);
/**
* This method will set the internal Old Value which is used to track dirty state, to the current value of the field. This effectively resets the dirty state of the field to false. Use this method sparingly.
*/
ResetOldValue(): void;
/**
* Returns the old value of the field. This is the value that was set when the field was last loaded from the database.
*/
get OldValue(): any;

@@ -53,2 +83,5 @@ }

}
/**
* Base class used for all entity objects. This class is abstract and is sub-classes for each particular entity using the CodeGen tool. This class provides the basic functionality for loading, saving, and validating entity objects.
*/
export declare abstract class BaseEntity {

@@ -65,10 +98,32 @@ private _EntityInfo;

get IsSaved(): boolean;
/**
* Transaction Groups are used to group multiple transactions into a single ATOMic transaction in a database. They are also useful even in situations with ATOMicity is less important but you want
* to submit a group of changes to the API server in a single network call.
*/
get TransactionGroup(): TransactionGroupBase;
set TransactionGroup(group: TransactionGroupBase);
/**
* Access to the underlying metadata for the entity object.
*/
get EntityInfo(): EntityInfo;
get Fields(): EntityField[];
/**
* Convenience method to access a field by name. This method is case-insensitive and will return null if the field is not found. You can do the same thing with more fine tune controlled by accessing the Fields property directly.
* @param fieldName
* @returns
*/
GetFieldByName(fieldName: string): EntityField;
get Dirty(): boolean;
/**
* Returns the primary key field for the entity. If the entity has a composite primary key, this method will return the first primary key field.
*/
get PrimaryKey(): EntityField;
/**
* Returns an array of all primary key fields for the entity. If the entity has a composite primary key, this method will return an array of all primary key fields.
* If the entity has a single primary key, this method will return an array with a single field in it.
*/
get PrimaryKeys(): EntityField[];
/**
* Returns true if the record has been loaded from the database, false otherwise. This is useful to check to see if the record is in a "New Record" state or not.
*/
get RecordLoaded(): boolean;

@@ -93,4 +148,11 @@ /**

SetMany(object: any, ignoreNonExistentFields?: boolean): void;
GetAll(oldValues?: boolean): {};
/**
* Utility method to create an object and return it with properties in the newly created and returned object for each field in the entity object. This is useful for scenarios where you need to be able to persist the data
* in a format to send to a network call, save to a file or database, etc. This method will return an object with properties that match the field names of the entity object.
* @param oldValues When set to true, the old values of the fields will be returned instead of the current values.
* @param onlyDirtyFields When set to true, only the fields that are dirty will be returned.
* @returns
*/
GetAll(oldValues?: boolean, onlyDirtyFields?: boolean): {};
/**
* This utility method calls GetDataObject() internally and formats the result as a JSON string. If you want to get the data as an object instead of a string, call GetDataObject() directly.

@@ -118,2 +180,7 @@ * @param params

CopyFrom(other: BaseEntity, includePrimaryKeys?: boolean): boolean;
/**
* The ContextCurrentUser is a property used to manually set the "current" user for scenarios, primarily on the server side, where the user changes per request. For situations where there is no global CurrentUser in the Metadata.Provider,
* you MUST set this property to the user you want to use for the current operation. If you used Metadata.GetEntityObject() to get the entity object, this property will be set automatically for you as that method has a parameter that can
* be provided for the ContextCurrentUser.
*/
set ContextCurrentUser(user: UserInfo);

@@ -132,2 +199,5 @@ get ContextCurrentUser(): UserInfo;

Save(options?: EntitySaveOptions): Promise<boolean>;
/**
* Internal helper method for the class and sub-classes - used to easily get the Active User which is either the ContextCurrentUser, if defined, or the Metadata.Provider.CurrentUser if not.
*/
protected get ActiveUser(): UserInfo;

@@ -192,3 +262,3 @@ /**

/**
* Returns a list of changes made to this record, over time. Keep in mind this is only going to return valid data if you have the TrackRecordChanges bit set to 1 on the entity you're working with.
* Returns a list of changes made to this record, over time. Only works if TrackRecordChanges bit set to 1 on the entity you're working with.
*/

@@ -202,4 +272,4 @@ get RecordChanges(): Promise<RecordChange[]>;

*/
static GetRecordChanges(entityName: string, PrimaryKeyValue: any): Promise<RecordChange[]>;
static GetRecordChanges(entityName: string, PrimaryKeyValues: PrimaryKeyValue[]): Promise<RecordChange[]>;
}
//# sourceMappingURL=baseEntity.d.ts.map

@@ -10,2 +10,6 @@ "use strict";

const logging_1 = require("./logging");
/**
* Represents a field in an entity. This class is used to store the value of the field, dirty state, as well as other run-time information about the field. The class encapsulates the underlying field metadata and exposes some of the more commonly
* used properties from the entity field metadata.
*/
class EntityField {

@@ -36,2 +40,5 @@ get Name() {

}
/**
* Returns the current value of the field.
*/
get Value() {

@@ -46,2 +53,5 @@ return this._Value;

}
/**
* Sets the value of the field. If the field is read only, nothing happens. If the field is not read only, the value is set and the internal representation of the dirty flag is flipped if the value is different from the old value.
*/
set Value(value) {

@@ -52,5 +62,5 @@ if (!this.ReadOnly ||

this._Value = value;
// in the below, we set the OldValue, but only if (a) we have never set the value before, or (b) the value or the old value is not null - which means that we are in a record setup scenario
if (this._NeverSet &&
//this._OldValue == null && ---- we used to check _OldValue == null, but actually that doesn't make any sense because we don't care about the old value here, we just care that _NeverSet === true
value != null) {
(value !== null || this._OldValue !== null)) {
// initial value set

@@ -62,2 +72,5 @@ this._OldValue = value;

}
/**
* Returns true if the field is dirty, false otherwise. A field is considered dirty if the value is different from the old value. If the field is read only, it is never dirty.
*/
get Dirty() {

@@ -86,5 +99,16 @@ if (this.ReadOnly)

}
/**
* Convenience method to format the value of the field. This method calls the static method on EntityFieldInfo to do the actual formatting.
* @param decimals
* @param currency
* @returns
*/
FormatValue(decimals = 2, currency = 'USD') {
return this.EntityFieldInfo.FormatValue(this.Value, decimals, currency);
}
/**
* Validates the current value of the field. If the field is read only, or if the field is marked to skip validation, nothing happens.
* If the field is not read only, and the field is not marked to skip validation, the value is checked against the validation rules defined in the metadata for the field.
* @returns
*/
Validate() {

@@ -183,5 +207,11 @@ const ef = this._entityFieldInfo;

}
/**
* This method will set the internal Old Value which is used to track dirty state, to the current value of the field. This effectively resets the dirty state of the field to false. Use this method sparingly.
*/
ResetOldValue() {
this._OldValue = this.Value;
}
/**
* Returns the old value of the field. This is the value that was set when the field was last loaded from the database.
*/
get OldValue() {

@@ -209,2 +239,5 @@ return this._OldValue;

exports.BaseEntityAIActionParams = BaseEntityAIActionParams;
/**
* Base class used for all entity objects. This class is abstract and is sub-classes for each particular entity using the CodeGen tool. This class provides the basic functionality for loading, saving, and validating entity objects.
*/
class BaseEntity {

@@ -226,2 +259,6 @@ constructor(Entity) {

}
/**
* Transaction Groups are used to group multiple transactions into a single ATOMic transaction in a database. They are also useful even in situations with ATOMicity is less important but you want
* to submit a group of changes to the API server in a single network call.
*/
get TransactionGroup() {

@@ -233,2 +270,5 @@ return this._transactionGroup;

}
/**
* Access to the underlying metadata for the entity object.
*/
get EntityInfo() {

@@ -240,2 +280,7 @@ return this._EntityInfo;

}
/**
* Convenience method to access a field by name. This method is case-insensitive and will return null if the field is not found. You can do the same thing with more fine tune controlled by accessing the Fields property directly.
* @param fieldName
* @returns
*/
GetFieldByName(fieldName) {

@@ -247,2 +292,5 @@ return this.Fields.find(f => f.Name.trim().toLowerCase() == fieldName.trim().toLowerCase());

}
/**
* Returns the primary key field for the entity. If the entity has a composite primary key, this method will return the first primary key field.
*/
get PrimaryKey() {

@@ -256,5 +304,12 @@ const fieldInfo = this.EntityInfo.PrimaryKey;

}
/**
* Returns an array of all primary key fields for the entity. If the entity has a composite primary key, this method will return an array of all primary key fields.
* If the entity has a single primary key, this method will return an array with a single field in it.
*/
get PrimaryKeys() {
return this.EntityInfo.PrimaryKeys.map(pk => this.GetFieldByName(pk.Name));
}
/**
* Returns true if the record has been loaded from the database, false otherwise. This is useful to check to see if the record is in a "New Record" state or not.
*/
get RecordLoaded() {

@@ -320,8 +375,17 @@ return this._recordLoaded;

}
GetAll(oldValues = false) {
/**
* Utility method to create an object and return it with properties in the newly created and returned object for each field in the entity object. This is useful for scenarios where you need to be able to persist the data
* in a format to send to a network call, save to a file or database, etc. This method will return an object with properties that match the field names of the entity object.
* @param oldValues When set to true, the old values of the fields will be returned instead of the current values.
* @param onlyDirtyFields When set to true, only the fields that are dirty will be returned.
* @returns
*/
GetAll(oldValues = false, onlyDirtyFields = false) {
let obj = {};
for (let field of this.Fields) {
obj[field.Name] = oldValues ? field.OldValue : field.Value;
if (field.EntityFieldInfo.TSType == entityInfo_1.EntityFieldTSType.Date && obj[field.Name] && !(obj[field.Name] instanceof Date)) {
obj[field.Name] = new Date(obj[field.Name]); // a timestamp, convert to JS Date Object
if (!onlyDirtyFields || (onlyDirtyFields && field.Dirty)) {
obj[field.Name] = oldValues ? field.OldValue : field.Value;
if (field.EntityFieldInfo.TSType == entityInfo_1.EntityFieldTSType.Date && obj[field.Name] && !(obj[field.Name] instanceof Date)) {
obj[field.Name] = new Date(obj[field.Name]); // a timestamp, convert to JS Date Object
}
}

@@ -420,2 +484,7 @@ }

}
/**
* The ContextCurrentUser is a property used to manually set the "current" user for scenarios, primarily on the server side, where the user changes per request. For situations where there is no global CurrentUser in the Metadata.Provider,
* you MUST set this property to the user you want to use for the current operation. If you used Metadata.GetEntityObject() to get the entity object, this property will be set automatically for you as that method has a parameter that can
* be provided for the ContextCurrentUser.
*/
set ContextCurrentUser(user) {

@@ -468,2 +537,5 @@ this._contextCurrentUser = user;

}
/**
* Internal helper method for the class and sub-classes - used to easily get the Active User which is either the ContextCurrentUser, if defined, or the Metadata.Provider.CurrentUser if not.
*/
get ActiveUser() {

@@ -657,7 +729,7 @@ return this.ContextCurrentUser || metadata_1.Metadata.Provider.CurrentUser; // use the context user ahead of the Provider.Current User - this is for SERVER side ops where the user changes per request

/**
* Returns a list of changes made to this record, over time. Keep in mind this is only going to return valid data if you have the TrackRecordChanges bit set to 1 on the entity you're working with.
* Returns a list of changes made to this record, over time. Only works if TrackRecordChanges bit set to 1 on the entity you're working with.
*/
get RecordChanges() {
if (this.IsSaved)
return BaseEntity.GetRecordChanges(this.EntityInfo.Name, this.PrimaryKey.Value);
return BaseEntity.GetRecordChanges(this.EntityInfo.Name, this.PrimaryKeys.map(pk => { return { FieldName: pk.Name, Value: pk.Value }; }));
else

@@ -672,3 +744,3 @@ throw new Error('Cannot get record changes for a record that has not been saved yet');

*/
static async GetRecordChanges(entityName, PrimaryKeyValue) {
static async GetRecordChanges(entityName, PrimaryKeyValues) {
if (BaseEntity.Provider === null) {

@@ -678,3 +750,3 @@ throw new Error('No provider set');

else {
const results = await BaseEntity.Provider.GetRecordChanges(entityName, PrimaryKeyValue);
const results = await BaseEntity.Provider.GetRecordChanges(entityName, PrimaryKeyValues);
if (results) {

@@ -681,0 +753,0 @@ const changes = [];

@@ -234,2 +234,3 @@ import { BaseInfo } from "./baseInfo";

*/
private _codeName;
get CodeName(): string;

@@ -412,2 +413,5 @@ get GraphQLType(): EntityFieldGraphQLType;

export type ValidationErrorType = typeof ValidationErrorType[keyof typeof ValidationErrorType];
/**
* Information about a single validation error
*/
export declare class ValidationErrorInfo {

@@ -420,2 +424,5 @@ Source: string;

}
/**
* The result of a validation check
*/
export declare class ValidationResult {

@@ -422,0 +429,0 @@ Success: boolean;

19

dist/generic/entityInfo.js

@@ -249,8 +249,7 @@ "use strict";

}
/**
* For fields in the database that have spaces in them, we need to replace the spaces with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
*/
get CodeName() {
// the code below replaces spaces with _
return this.Name.replace(/\s/g, "_");
// the code below replaces spaces with _ and stashes the result in a private variable so we only do this once
if (this._codeName == null)
this._codeName = this.Name.replace(/\s/g, "_");
return this._codeName;
}

@@ -394,2 +393,6 @@ get GraphQLType() {

this.RelatedEntityClassName = null;
/**
* For fields in the database that have spaces in them, we need to replace the spaces with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
*/
this._codeName = null;
if (initData) {

@@ -796,2 +799,5 @@ this.copyInitData(initData);

};
/**
* Information about a single validation error
*/
class ValidationErrorInfo {

@@ -806,2 +812,5 @@ constructor(Source, Message, Value, Type = exports.ValidationErrorType.Failure) {

exports.ValidationErrorInfo = ValidationErrorInfo;
/**
* The result of a validation check
*/
class ValidationResult {

@@ -808,0 +817,0 @@ constructor() {

@@ -13,2 +13,6 @@ import { DatasetItemFilterType, DatasetResultType, DatasetStatusResultType, EntityRecordNameInput, EntityRecordNameResult, ILocalStorageProvider, IMetadataProvider, PotentialDuplicateRequest, PotentialDuplicateResponse, ProviderConfigDataBase, ProviderType } from "./interfaces";

private static _globalProviderKey;
/**
* When an application initializes, the Provider package that is being used for that application will handle setting the provider globally via this static property.
* This is done so that the provider can be accessed from anywhere in the application without having to pass it around. This pattern is used sparingly in MJ.
*/
static get Provider(): IMetadataProvider;

@@ -15,0 +19,0 @@ static set Provider(value: IMetadataProvider);

@@ -9,2 +9,6 @@ "use strict";

class Metadata {
/**
* When an application initializes, the Provider package that is being used for that application will handle setting the provider globally via this static property.
* This is done so that the provider can be accessed from anywhere in the application without having to pass it around. This pattern is used sparingly in MJ.
*/
static get Provider() {

@@ -11,0 +15,0 @@ const g = global_1.MJGlobal.Instance.GetGlobalObjectStore();

import { BaseInfo } from "./baseInfo";
import { EntityInfo } from "./entityInfo";
/**
* Metadata about a single stored query in the database.
*/
export declare class QueryInfo extends BaseInfo {

@@ -4,0 +7,0 @@ Name: string;

@@ -6,2 +6,5 @@ "use strict";

const metadata_1 = require("./metadata");
/**
* Metadata about a single stored query in the database.
*/
class QueryInfo extends baseInfo_1.BaseInfo {

@@ -8,0 +11,0 @@ get Fields() {

@@ -6,2 +6,5 @@ import { IRunQueryProvider, RunQueryResult } from './interfaces';

};
/**
* Class used to run a query and return the results.
*/
export declare class RunQuery {

@@ -8,0 +11,0 @@ RunQuery(params: RunQueryParams, contextUser?: UserInfo): Promise<RunQueryResult>;

@@ -5,2 +5,5 @@ "use strict";

const global_1 = require("@memberjunction/global");
/**
* Class used to run a query and return the results.
*/
class RunQuery {

@@ -7,0 +10,0 @@ async RunQuery(params, contextUser) {

@@ -6,2 +6,5 @@ import { IRunReportProvider, RunReportResult } from './interfaces';

};
/**
* Class used to run a report and return the results.
*/
export declare class RunReport {

@@ -8,0 +11,0 @@ RunReport(params: RunReportParams, contextUser?: UserInfo): Promise<RunReportResult>;

@@ -5,2 +5,5 @@ "use strict";

const global_1 = require("@memberjunction/global");
/**
* Class used to run a report and return the results.
*/
class RunReport {

@@ -7,0 +10,0 @@ //private static _Provider: IRunViewProvider;

@@ -98,3 +98,3 @@ import { IRunViewProvider, RunViewResult } from '../generic/interfaces';

/**
* Class for runnings views in a generic, tier-independent manner - uses a provider model for
* Class for running views in a generic, tier-independent manner - uses a provider model for
* implementation transparently from the viewpoint of the consumer of the class.

@@ -101,0 +101,0 @@ */

@@ -7,3 +7,3 @@ "use strict";

/**
* Class for runnings views in a generic, tier-independent manner - uses a provider model for
* Class for running views in a generic, tier-independent manner - uses a provider model for
* implementation transparently from the viewpoint of the consumer of the class.

@@ -10,0 +10,0 @@ */

{
"name": "@memberjunction/core",
"version": "1.0.9",
"version": "1.0.11",
"description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities",

@@ -22,4 +22,4 @@ "main": "dist/index.js",

"dependencies": {
"@memberjunction/global": "^1.0.9"
"@memberjunction/global": "^1.0.11"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc