Skip to content

Commit

Permalink
Merge pull request #3 from plblum/feature-work-04042024
Browse files Browse the repository at this point in the history
Feature work 04042024
  • Loading branch information
plblum authored Apr 4, 2024
2 parents 07b4a0e + daa0206 commit c435698
Show file tree
Hide file tree
Showing 16 changed files with 11,750 additions and 10,258 deletions.
21,331 changes: 11,501 additions & 9,830 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
],

"dependencies": {
"gulp-jest": "^4.0.4"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"gulp-jest": "^4.0.4",
"eslint": "^8.57.0",
"eslint-plugin-typescript": "^0.14.0",
"gulp": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/jivs-engine/src/Conditions/ConditionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export abstract class ConditionBase<TConditionDescriptor extends ConditionDescri
/**
* A unique identifier for the specific implementation, like "Required" or "Range".
* Its value appears in the IssueFound that comes from Validation, and in
* IssueSnapshot that comes from retrieving a list of errors to display.
* IssueFound that comes from retrieving a list of errors to display.
* It allows the consumer of both to correlate those instances with the specific condition.
* When defining conditions through a ConditionDescriptor, the Type property must
* be assigned with a valid ConditionType.
Expand Down
9 changes: 8 additions & 1 deletion packages/jivs-engine/src/Interfaces/Conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ICondition {
/**
* A unique identifier for the specific implementation, like "Required" or "Range".
* Its value appears in the IssueFound that comes from Validation, and in
* IssueSnapshot that comes from retrieving a list of errors to display.
* IssueFound that comes from retrieving a list of errors to display.
* It allows the consumer of both to correlate those instances with the specific condition.
* When defining conditions through a ConditionDescriptor, the Type property must
* be assigned with a valid ConditionType.
Expand Down Expand Up @@ -108,6 +108,13 @@ export interface ConditionDescriptor {
* and supply a value when the Condition does not.
*/
category?: ConditionCategory;

/**
* Handy way to allow users to enter known properties without getting ts errors.
* However, they can improve things if they typecast to the appropriate
* condition's Descriptor.
*/
[propName: string]: any;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/jivs-engine/src/Interfaces/InputValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ export interface InputValidatorDescriptor {
* the value from the errorMessage property is used.
*/
summaryMessagel10n?: string | null | undefined;

/**
* Handy way to allow users to enter known properties without getting ts errors.
* However, they can improve things if they typecast to the appropriate
* inputValidator's Descriptor.
*/
[propName: string]: any;
}

/**
Expand Down
22 changes: 8 additions & 14 deletions packages/jivs-engine/src/Interfaces/InputValueHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ValueHostId } from '../DataTypes/BasicTypes';
import { IInputValidator, InputValidatorDescriptor } from './InputValidator';
import {
type ValidateOptions, type ValidateResult, ValidationResult,
type BusinessLogicError, type IssueFound, type IssueSnapshot, StatefulValidateResult
type BusinessLogicError, type IssueFound, StatefulValidateResult
} from './Validation';
import { IValueHostCallbacks, toIValueHostCallbacks, type IValueHost, type SetValueOptions, type ValueHostDescriptor, type ValueHostState } from './ValueHost';

Expand Down Expand Up @@ -100,7 +100,7 @@ export interface IInputValueHostBase extends IValueHost {
/**
* When Business Logic gathers data from the UI, it runs its own final validation.
* If its own business rule has been violated, it should be passed here where it becomes exposed to
* the Validation Summary (getIssuesForSummary) and optionally for an individual ValueHostId,
* the Validation Summary (getIssuesFound) and optionally for an individual ValueHostId,
* by specifying that valueHostId in AssociatedValueHostId.
* Each time called, it adds to the existing list. Use clearBusinessLogicErrors() first if starting a fresh list.
* @param error - An error to show.
Expand All @@ -120,20 +120,14 @@ export interface IInputValueHostBase extends IValueHost {
doNotSaveNativeValue(): boolean;

/**
* The results of the latest validate()
* @returns Issues found or null if none.
* The results of validation specific to one condiiton Type.
* @param conditionType
* @returns The issue or null if none.
*/
getIssuesFound(): Array<IssueFound> | null;
getIssueFound(conditionType: string): IssueFound | null;

/**
* Lists all error messages and supporting info about each validator
* for use by a input field/element that shows its own error messages (InputValueHostState.errorMessage)
* @returns
*/
getIssuesForInput(): Array<IssueSnapshot>;

/**
* A list of all issues to show in a Validation Summary widget optionally for a given group.
* A list of all issues found.
* @param group - Omit or null to ignore groups. Otherwise this will match to InputValueHosts with
* the same group (case insensitive match).
* @returns An array of 0 or more details of issues found. Each contains:
Expand All @@ -145,7 +139,7 @@ export interface IInputValueHostBase extends IValueHost {
* One is for Summary only. If that one wasn't supplied, the other (for local displaying message)
* is returned.
*/
getIssuesForSummary(group?: string): Array<IssueSnapshot>;
getIssuesFound(group?: string): Array<IssueFound>;

/**
* Returns the ConversionErrorTokenValue supplied by the latest call
Expand Down
11 changes: 1 addition & 10 deletions packages/jivs-engine/src/Interfaces/Validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,11 @@ export interface IssueFound {
}


/**
* Results for function that reveal error messages.
*/
export interface IssueSnapshot {
id: ValueHostId;
severity: ValidationSeverity;
errorMessage: string;
}

/**
* When Business Logic gathers data from the UI, it runs its own final validation.
* If its own business rule has been violated, it should be recorded with this interface
* and passed to ValidationManager.SetBusinessLogicErrors where it becomes exposed to
* the Validation Summary (getIssuesForSummary) and optionally for an individual ValueHostId,
* the Validation Summary (getIssuesFound) and optionally for an individual ValueHostId,
* by specifying that valueHostId in AssociatedValueHostId.
*/
export interface BusinessLogicError {
Expand Down
25 changes: 12 additions & 13 deletions packages/jivs-engine/src/Interfaces/ValidationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import { ValueHostId } from '../DataTypes/BasicTypes';
import { IValueHostsManager } from './ValueHostResolver';
import { ValidateOptions, ValidateResult, BusinessLogicError, IssueSnapshot } from './Validation';
import { ValidateOptions, ValidateResult, BusinessLogicError, IssueFound } from './Validation';
import { IValidationServices } from './ValidationServices';
import { ValueHostDescriptor, ValueHostState } from './ValueHost';
import { IInputValueHostCallbacks, toIInputValueHostCallbacks } from './InputValueHost';
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface IValidationManager extends IValueHostsManager {
/**
* When Business Logic gathers data from the UI, it runs its own final validation.
* If its own business rule has been violated, it should be passed here where it becomes exposed to
* the Validation Summary (getIssuesForSummary) and optionally for an individual ValueHostId,
* the Validation Summary (getIssuesFound) and optionally for an individual ValueHostId,
* by specifying that valueHostId in AssociatedValueHostId.
* Each time its called, all previous business logic errors are abandoned.
* @param errors - A list of business logic errors to show or null to indicate no errors.
Expand All @@ -86,28 +86,27 @@ export interface IValidationManager extends IValueHostsManager {
* @returns An array of 0 or more details of issues found. Each contains:
* - Id - The ID for the ValueHost that contains this error. Use to hook up a click in the summary
* that scrolls the associated input field/element into view and sets focus.
* - ConditionType - Identifies the condition supplying the issue.
* - Severity - Helps style the error. Expect Severe, Error, and Warning levels.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied, to
* show in the Validation Summary widget. Each InputValidator has 2 messages.
* One is for Summary only. If that one wasn't supplied, the other (for local displaying message)
* is returned.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied
* - summaryMessage - The message suited for a Validation Summary widget.
*/
getIssuesForInput(valueHostId: ValueHostId): Array<IssueSnapshot>;
getIssuesForInput(valueHostId: ValueHostId): Array<IssueFound>;

/**
* A list of all issues to show in a Validation Summary widget optionally for a given group.
* A list of all issues from all InputValueHosts optionally for a given group.
* Use with a Validation Summary widget and when validating the Model itself.
* @param group - Omit or null to ignore groups. Otherwise this will match to InputValueHosts with
* the same group (case insensitive match).
* @returns An array of 0 or more details of issues found. Each contains:
* - Id - The ID for the ValueHost that contains this error. Use to hook up a click in the summary
* that scrolls the associated input field/element into view and sets focus.
* - ConditionType - Identifies the condition supplying the issue.
* - Severity - Helps style the error. Expect Severe, Error, and Warning levels.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied, to
* show in the Validation Summary widget. Each InputValidator has 2 messages.
* One is for Summary only. If that one wasn't supplied, the other (for local displaying message)
* is returned.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied.
* - summaryMessage - The message suited for a Validation Summary widget.
*/
getIssuesForSummary(group?: string): Array<IssueSnapshot>;
getIssuesFound(group?: string): Array<IssueFound>;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/jivs-engine/src/Interfaces/ValueHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ export interface ValueHostDescriptor {
* If null, the current value's type (ValueHostState.Value) is used and must be string, number, boolean, or date.
*/
dataType?: string;

/**
* Handy way to allow users to enter known properties without getting ts errors.
* However, they can improve things if they typecast to the appropriate
* valueHost's Descriptor.
*/
[propName: string]: any;
}


Expand Down
2 changes: 1 addition & 1 deletion packages/jivs-engine/src/ValueHosts/InputValueHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export function toIInputValueHost(source: any): IInputValueHost | null
test.getInputValue !== undefined &&
test.setInputValue !== undefined &&
test.validate !== undefined &&
test.getIssuesForInput !== undefined)
test.getIssuesFound !== undefined)
return test;
}
return null;
Expand Down
71 changes: 21 additions & 50 deletions packages/jivs-engine/src/ValueHosts/InputValueHostBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ValueHostBase } from './ValueHostBase';
import type { IValueHostGenerator } from '../Interfaces/ValueHostFactory';
import { IValueHostResolver, IValueHostsManager, toIValueHostsManager } from '../Interfaces/ValueHostResolver';
import { IInputValueHost, IInputValueHostBase, InputValueHostBaseDescriptor, InputValueHostBaseState } from '../Interfaces/InputValueHost';
import { BusinessLogicError, IssueFound, IssueSnapshot, ValidateOptions, ValidateResult, ValidationResult, ValidationSeverity } from '../Interfaces/Validation';
import { BusinessLogicError, IssueFound, ValidateOptions, ValidateResult, ValidationResult, ValidationSeverity } from '../Interfaces/Validation';


/**
Expand Down Expand Up @@ -296,7 +296,7 @@ export abstract class InputValueHostBase<TDescriptor extends InputValueHostBaseD
/**
* When Business Logic gathers data from the UI, it runs its own final validation.
* If its own business rule has been violated, it should be passed here where it becomes exposed to
* the Validation Summary (getIssuesForSummary) and optionally for an individual ValueHostId,
* the Validation Summary (getIssuesFound) and optionally for an individual ValueHostId,
* by specifying that valueHostId in AssociatedValueHostId.
* Each time called, it adds to the existing list. Use clearBusinessLogicErrors() first if starting a fresh list.
* @param error - A business logic error to show.
Expand Down Expand Up @@ -334,6 +334,11 @@ export abstract class InputValueHostBase<TDescriptor extends InputValueHostBaseD
//#endregion business logic errors

//#region access to validation results
/**
* The results of validation specific to one condiiton Type.
* @param conditionType
* @returns The issue or null if none.
*/
public getIssueFound(conditionType: string): IssueFound | null {
if (!conditionType)
return null;
Expand All @@ -343,74 +348,40 @@ export abstract class InputValueHostBase<TDescriptor extends InputValueHostBaseD
value.conditionType === conditionType) ?? null) :
null;
}
/**
* The results of the latest validate()
* @returns Issues found or null if none.
*/
public getIssuesFound(): Array<IssueFound> | null {
return this.state.issuesFound;
}

/**
* Lists all error messages and supporting info about each validator
* for use by a input field/element that shows its own error messages (InputValueHostState.errorMessage)
* @returns
*/
public getIssuesForInput(): Array<IssueSnapshot> {
let id = this.getId();
let list: Array<IssueSnapshot> = [];

if (this.state.issuesFound) {
for (let issue of this.state.issuesFound) {
list.push({
id: id,
severity: issue.severity,
errorMessage: issue.errorMessage
});
}
}
this.addBusinessLogicErrorsToSnapshotList(list);

return list;
}

/**
* A list of all issues to show in a Validation Summary widget optionally for a given group.
* @param group - Omit or null to ignore groups. Otherwise this will match to InputValueHosts with
* the same group (case insensitive match).
* Lists all issues found (error messages and supporting info) for a single InputValueHost
* so the input field/element can show error messages and adjust its appearance.
* @returns An array of 0 or more details of issues found. Each contains:
* - Id - The ID for the ValueHost that contains this error. Use to hook up a click in the summary
* that scrolls the associated input field/element into view and sets focus.
* - ConditionType - Identifies the condition supplying the issue.
* - Severity - Helps style the error. Expect Severe, Error, and Warning levels.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied, to
* show in the Validation Summary widget. Each InputValidator has 2 messages.
* One is for Summary only. If that one wasn't supplied, the other (for local displaying message)
* is returned.
* - errorMessage - Fully prepared, tokens replaced and formatting rules applied
* - summaryMessage - The message suited for a Validation Summary widget.
*/
public getIssuesForSummary(group?: string): Array<IssueSnapshot> {
public getIssuesFound(group?: string): Array<IssueFound> {
let id = this.getId();
let list: Array<IssueSnapshot> = [];
let list: Array<IssueFound> = [];

if (this.state.issuesFound && groupsMatch(group, this.state.group)) {
for (let issue of this.state.issuesFound) {
list.push({
id: id,
severity: issue.severity,
errorMessage: issue.summaryMessage ?? issue.errorMessage
});
list.push(issue);
}
}
this.addBusinessLogicErrorsToSnapshotList(list);

return list;
}
private addBusinessLogicErrorsToSnapshotList(list: Array<IssueSnapshot>): void {
private addBusinessLogicErrorsToSnapshotList(list: Array<IssueFound>): void {
if (this.businessLogicErrors) {
for (let error of this.businessLogicErrors) {
list.push({
id: this.getId(),
valueHostId: this.getId(),
conditionType: error.errorCode ?? '',
severity: error.severity ?? ValidationSeverity.Error,
errorMessage: error.errorMessage
errorMessage: error.errorMessage,
summaryMessage: error.errorMessage
});
}
}
Expand Down Expand Up @@ -448,7 +419,7 @@ export function toIInputValueHostBase(source: any): IInputValueHostBase | null
if (test.getInputValue !== undefined &&
test.setInputValue !== undefined &&
test.validate !== undefined &&
test.getIssuesForInput !== undefined)
test.getIssuesFound !== undefined)
return test;
}
return null;
Expand Down
Loading

0 comments on commit c435698

Please sign in to comment.