Socket
Socket
Sign inDemoInstall

@flatfile/hooks

Package Overview
Dependencies
Maintainers
21
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flatfile/hooks - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

27

dist/index.d.ts
type TPrimitive = string | boolean | number | null;
type TRecordDataWithLinks<T extends TPrimitive | undefined = TPrimitive> = {
[key: string]: T | {
value: T;
links: TRecordData<TPrimitive>[];
};
};
type TRecordData<T extends TPrimitive | undefined = TPrimitive> = {

@@ -6,3 +12,3 @@ [key: string]: T;

interface IRawRecord {
rawData: TRecordData;
rawData: TRecordDataWithLinks;
rowId: number | string;

@@ -12,3 +18,3 @@ }

type TRecordStageLevel = 'cast' | 'empty' | 'required' | 'compute' | 'validate' | 'apply' | 'other';
interface IRecordInfo<M extends TRecordData = TRecordData, K = keyof M> {
interface IRecordInfo<M extends TRecordDataWithLinks = TRecordDataWithLinks, K = keyof M> {
level: TRecordInfoLevel;

@@ -19,3 +25,3 @@ field: K;

}
interface IRawRecordWithInfo<M extends TRecordData = TRecordData> {
interface IRawRecordWithInfo<M extends TRecordDataWithLinks = TRecordDataWithLinks> {
row: IRawRecord;

@@ -35,3 +41,3 @@ info: IRecordInfo<M>[];

}
declare class FlatfileRecord<M extends TRecordData = TRecordData> {
declare class FlatfileRecord<M extends TRecordDataWithLinks = TRecordDataWithLinks> {
private readonly data;

@@ -46,6 +52,11 @@ private readonly mutated;

private verifyField;
set(field: string, value: TPrimitive): this;
private isLinkedField;
set(field: string, value: TPrimitive): this | undefined;
setLinkedValue(linkedFieldKey: string, childKey: string, value: TPrimitive): this;
get(field: string): null | TPrimitive;
getLinkedValue(linkedFieldKey: string, childKey: string): string | number | boolean | null;
getLinks(field: string): any;
getLinkedValue(linkedFieldKey: string, childKey: string): string | number | boolean | {
value: TPrimitive;
links: TRecordData<TPrimitive>[];
} | null;
addInfo(fields: string | string[], message: string): this;

@@ -62,3 +73,3 @@ /**

declare class FlatfileRecords<M extends TRecordData> {
declare class FlatfileRecords<M extends TRecordDataWithLinks> {
private readonly _records;

@@ -84,2 +95,2 @@ constructor(rawRecords: IRawRecord[]);

export { FlatfileRecord, FlatfileRecords, FlatfileSession, IPayload, IRawRecord, IRawRecordWithInfo, IRecordInfo, TPrimitive, TRecordData, TRecordInfoLevel, TRecordStageLevel };
export { FlatfileRecord, FlatfileRecords, FlatfileSession, IPayload, IRawRecord, IRawRecordWithInfo, IRecordInfo, TPrimitive, TRecordData, TRecordDataWithLinks, TRecordInfoLevel, TRecordStageLevel };

@@ -30,2 +30,3 @@ "use strict";

// src/classes/FlatfileRecord.ts
var propExists = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
var FlatfileRecord = class {

@@ -47,4 +48,4 @@ constructor(raw) {

}
verifyField(field) {
if (!Object.prototype.hasOwnProperty.call(this.data, field)) {
verifyField(field, data) {
if (!propExists(data || this.data, field)) {
console.error(`Record does not have field "${field}".`);

@@ -55,2 +56,6 @@ return false;

}
isLinkedField(field) {
const fieldValue = this.mutated[field];
return !!fieldValue && typeof fieldValue === "object" && propExists(fieldValue, "value") && propExists(fieldValue, "links");
}
set(field, value) {

@@ -60,5 +65,19 @@ if (!this.verifyField(field)) {

}
Object.defineProperty(this.mutated, field, {
value
});
const isLinked = this.isLinkedField(field);
if (isLinked) {
const fieldValue = this.mutated[field];
if (!!fieldValue && typeof fieldValue === "object" && propExists(fieldValue, "value") && fieldValue.value === value) {
return;
} else {
Object.defineProperty(this.mutated, field, {
value: {
value
}
});
}
} else {
Object.defineProperty(this.mutated, field, {
value
});
}
return this;

@@ -75,6 +94,29 @@ }

if (this.verifyField(field)) {
return this.mutated[field];
const value = this.mutated[field];
if (!!value && typeof value === "object" && propExists(value, "value")) {
return value.value;
}
return value;
}
return null;
}
getLinks(field) {
if (this.verifyField(field)) {
const fieldValue = this.mutated[field];
if (!fieldValue)
return null;
if (typeof fieldValue === "object") {
const { links } = fieldValue;
if (!links) {
console.error("Field is has no links.");
return null;
}
return links;
} else if (typeof fieldValue === "string") {
console.error("Field is not a ReferenceField.");
return fieldValue;
}
}
return null;
}
getLinkedValue(linkedFieldKey, childKey) {

@@ -81,0 +123,0 @@ var _a;

{
"name": "@flatfile/hooks",
"version": "1.2.1",
"version": "1.2.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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