@flatfile/hooks
Advanced tools
Comparing version 1.4.0 to 1.5.0
type TPrimitive = string | boolean | number | null; | ||
type TRecordValue = TPrimitive | Array<TPrimitive>; | ||
type TRecordDataWithLinks<T extends TPrimitive | undefined = TPrimitive> = { | ||
[key: string]: T | { | ||
value: T; | ||
value: T | Array<T>; | ||
links: TRecordData<TPrimitive>[]; | ||
@@ -23,2 +24,3 @@ }; | ||
stage: TRecordStageLevel; | ||
path?: string; | ||
} | ||
@@ -81,26 +83,26 @@ interface IRawRecordWithInfo<M extends TRecordDataWithLinks = TRecordDataWithLinks> { | ||
*/ | ||
get obj(): Record<string, TPrimitive>; | ||
get obj(): Record<string, TRecordValue>; | ||
private verifyField; | ||
private isLinkedField; | ||
set(field: string, value: TPrimitive): this | undefined; | ||
set(field: string, value: TRecordValue): this | undefined; | ||
setMetadata(data: Object): this; | ||
setLinkedValue(linkedFieldKey: string, childKey: string, value: TPrimitive): this; | ||
get(field: string): null | TPrimitive; | ||
get(field: string): null | TRecordValue; | ||
getMetadata(): Object; | ||
getLinks(field: string): TRecordData<TPrimitive>[] | null; | ||
getLinkedValue(linkedFieldKey: string, childKey: string): string | number | boolean | { | ||
value: TPrimitive; | ||
value: TPrimitive | TPrimitive[]; | ||
links: TRecordData<TPrimitive>[]; | ||
} | null; | ||
addInfo(fields: string | string[], message: string): this; | ||
addInfo(fields: string | string[], message: string, listItem?: string): this; | ||
/** | ||
* @alias addInfo | ||
*/ | ||
addComment(fields: string | string[], message: string): this; | ||
addError(fields: string | string[], message: string): this; | ||
addWarning(fields: string | string[], message: string): this; | ||
pushInfoMessage(fields: string | string[], message: string, level: IRecordInfo['level'], stage: TRecordStageLevel): this; | ||
compute(field: string, transformation: (value: TPrimitive, record: FlatfileRecord<M>) => TPrimitive, message?: string): this; | ||
computeIfPresent(field: string, transformation: (value: TPrimitive, record: FlatfileRecord<M>) => TPrimitive, message?: string): this; | ||
validate(field: string, validator: (value: TPrimitive, record: FlatfileRecord<M>) => boolean, message: string): this; | ||
addComment(fields: string | string[], message: string, listItem?: string): this; | ||
addError(fields: string | string[], message: string, listItem?: string): this; | ||
addWarning(fields: string | string[], message: string, listItem?: string): this; | ||
pushInfoMessage(fields: string | string[], message: string, level: IRecordInfo['level'], stage: TRecordStageLevel, listItem?: string): this; | ||
compute(field: string, transformation: (value: TRecordValue, record: FlatfileRecord<M>) => TRecordValue, message?: string): this; | ||
computeIfPresent(field: string, transformation: (value: TRecordValue, record: FlatfileRecord<M>) => TRecordValue, message?: string): this; | ||
validate(field: string, validator: (value: TRecordValue, record: FlatfileRecord<M>) => boolean, message: string): this; | ||
toJSON(): IRawRecordWithInfo<M>; | ||
@@ -130,2 +132,2 @@ } | ||
export { FlatfileRecord, FlatfileRecords, FlatfileSession, IPayload, IRawRecord, IRawRecordWithInfo, IRecordInfo, TPrimitive, TRecordData, TRecordDataWithLinks, TRecordInfoLevel, TRecordStageLevel }; | ||
export { FlatfileRecord, FlatfileRecords, FlatfileSession, IPayload, IRawRecord, IRawRecordWithInfo, IRecordInfo, TPrimitive, TRecordData, TRecordDataWithLinks, TRecordInfoLevel, TRecordStageLevel, TRecordValue }; |
@@ -191,4 +191,4 @@ "use strict"; | ||
} | ||
addInfo(fields, message) { | ||
return this.pushInfoMessage(fields, message, "info", "other"); | ||
addInfo(fields, message, listItem) { | ||
return this.pushInfoMessage(fields, message, "info", "other", listItem); | ||
} | ||
@@ -198,15 +198,23 @@ /** | ||
*/ | ||
addComment(fields, message) { | ||
return this.addInfo(fields, message); | ||
addComment(fields, message, listItem) { | ||
return this.addInfo(fields, message, listItem); | ||
} | ||
addError(fields, message) { | ||
return this.pushInfoMessage(fields, message, "error", "other"); | ||
addError(fields, message, listItem) { | ||
return this.pushInfoMessage(fields, message, "error", "other", listItem); | ||
} | ||
addWarning(fields, message) { | ||
return this.pushInfoMessage(fields, message, "warn", "other"); | ||
addWarning(fields, message, listItem) { | ||
return this.pushInfoMessage(fields, message, "warn", "other", listItem); | ||
} | ||
pushInfoMessage(fields, message, level, stage) { | ||
pushInfoMessage(fields, message, level, stage, listItem) { | ||
fields = Array.isArray(fields) ? fields : [fields]; | ||
fields.forEach((field) => { | ||
if (this.verifyField(field)) { | ||
let path = void 0; | ||
if (listItem) { | ||
const fieldValue = this.get(field); | ||
if (fieldValue && typeof fieldValue === "object") { | ||
const index = fieldValue.findIndex((value) => value === listItem); | ||
path = `$.value[${index}]`; | ||
} | ||
} | ||
this._info.push({ | ||
@@ -216,3 +224,4 @@ field, | ||
level, | ||
stage | ||
stage, | ||
path | ||
}); | ||
@@ -219,0 +228,0 @@ } |
{ | ||
"name": "@flatfile/hooks", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24102
718