Gathering detailed insights and metrics for @flatfile/plugin-record-hook
Gathering detailed insights and metrics for @flatfile/plugin-record-hook
Gathering detailed insights and metrics for @flatfile/plugin-record-hook
Gathering detailed insights and metrics for @flatfile/plugin-record-hook
Library of open-source plugins for developing with the Flatfile Platform
npm install @flatfile/plugin-record-hook
Typescript
Module System
Min. Node Version
Node Version
NPM Version
49.4
Supply Chain
93
Quality
96.6
Maintenance
100
Vulnerability
99.3
License
@flatfile/plugin-convert-sql-ddl@0.4.1
Published on 19 Dec 2024
@flatfile/plugin-convert-yaml-schema@0.5.1
Published on 19 Dec 2024
@flatfile/plugin-zip-extractor@0.8.1
Published on 19 Dec 2024
@flatfile/plugin-space-configure@0.8.1
Published on 19 Dec 2024
@flatfile/plugin-convert-openapi-schema@0.6.1
Published on 19 Dec 2024
@flatfile/plugin-connect-via-merge@0.6.1
Published on 19 Dec 2024
TypeScript (96.76%)
JavaScript (2.46%)
HTML (0.78%)
Total Downloads
1,091,140
Last Day
526
Last Week
33,948
Last Month
128,556
Last Year
974,756
6 Stars
664 Commits
8 Forks
6 Watching
35 Branches
25 Contributors
Latest Version
1.11.2
Package Id
@flatfile/plugin-record-hook@1.11.2
Unpacked Size
121.72 kB
Size
12.95 kB
File Count
13
NPM Version
10.8.2
Node Version
18.20.5
Publised On
10 Dec 2024
Cumulative downloads
Total Downloads
Last day
10.3%
526
Compared to previous day
Last week
-0.4%
33,948
Compared to previous week
Last month
4.9%
128,556
Compared to previous month
Last year
737.5%
974,756
Compared to previous year
1
3
2
The @flatfile/plugin-record-hook
plugin offers a convenient way to execute
custom logic on individual data records within Flatfile. By setting up an event
listener for the commit:created
event, this plugin seamlessly integrates with
the data processing flow.
Event Type:
listener.on('commit:created')
sheetSlug
- string
The sheetSlug
parameter is the slug of the sheet you want to listen to.
callback
- function
The callback
parameter takes a function that will be run on the record or records.
options.chunkSize
- number
- default: 10_000
- (optional)The chunkSize
parameter allows you to specify the quantity of records to process in each chunk.
options.parallel
- number
- default: 1
- (optional)The parallel
parameter allows you to specify the number of chunks to process in parallel.
options.debug
- boolean
- default: false
- (optional)The debug
parameter allows you to turn on debug logging.
1npm i @flatfile/plugin-record-hook @flatfile/hooks
1import { FlatfileRecord, bulkRecordHook } from "@flatfile/plugin-record-hook"; 2import { FlatfileEvent, FlatfileListener } from "@flatfile/listener";
1import { FlatfileRecord, recordHook } from "@flatfile/plugin-record-hook"; 2import { FlatfileEvent, FlatfileListener } from "@flatfile/listener";
Pass bulkRecordHook
or recordHook
to a Flatfile data listener and provide a function to run when data is added or updated.
Set up a listener to configure Flatfile and respond to data Events. Then use this plugin to set up a hook that responds to data changes.
bulkRecordHook.js
1import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 2 3export default async function (listener) { 4 listener.use( 5 bulkRecordHook("my-sheet", (records) => { 6 return records.map((r) => { 7 //do your work here 8 return r; 9 }); 10 }) 11 ); 12}
recordHook.js
1import { recordHook } from "@flatfile/plugin-record-hook"; 2 3export default async function (listener) { 4 listener.use( 5 recordHook("my-sheet", (record) => { 6 //do your work here 7 return record; 8 }) 9 ); 10}
bulkRecordHook.ts
1import { FlatfileRecord } from "@flatfile/hooks"; 2import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 3import { FlatfileListener } from "@flatfile/listener"; 4 5export default async function (listener: FlatfileListener) { 6 listener.use( 7 bulkRecordHook("my-sheet", (records: FlatfileRecord[]) => { 8 return records.map((r) => { 9 //do your work here 10 return r; 11 }); 12 }) 13 ); 14}
recordHook.ts
1import { FlatfileRecord } from "@flatfile/hooks"; 2import { recordHook } from "@flatfile/plugin-record-hook"; 3import { FlatfileListener } from "@flatfile/listener"; 4 5export default async function (listener: FlatfileListener) { 6 listener.use( 7 recordHook("my-sheet", (record: FlatfileRecord) => { 8 //do your work here 9 return record; 10 }) 11 ); 12}
bulkRecordHook
can accept additional properties. Props will be passed along to the transformer.
bulkRecordHook.js
1import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 2 3export default async function (listener) { 4 listener.use( 5 bulkRecordHook("my-sheet", (records) => { 6 return records.map((r) => { 7 //do your work here 8 return r; 9 }); 10 }), 11 { chunkSize: 100, parallel: 2 } 12 ); 13}
bulkRecordHook.ts
1import { FlatfileRecord } from "@flatfile/hooks"; 2import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 3import { FlatfileListener } from "@flatfile/listener"; 4 5export default async function (listener: FlatfileListener) { 6 listener.use( 7 bulkRecordHook( 8 "my-sheet", 9 (records: FlatfileRecord[]) => { 10 return records.map((r) => { 11 //do your work here 12 return r; 13 }); 14 }, 15 { chunkSize: 100, parallel: 2 } 16 ) 17 ); 18}
chunkSize
number default: 10_000 (optional)Define how many records you want to process in each batch. This allows you to balance efficiency and resource utilization based on your specific use case.
parallel
number default: 1 (optional)Choose whether the records should be processed in parallel. This enables you to optimize the execution time when dealing with large datasets.
This example sets up a record hook using listener.use
to modify records in the "my-sheet" sheet.
When a record is processed by the hook, it checks if an email address is missing, empty, or invalid, and if so, it logs corresponding error messages and adds them to a form validation context (if the r object is related to form validation). This helps ensure that only valid email addresses are accepted in the application.
In the bulkRecordHook
example, it passes a chunkSize
of 100 and asks the hooks to run 2 at a time via the parallel
property.
bulkRecordHook.js
1import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 2 3export default async function (listener) { 4 listener.use( 5 bulkRecordHook( 6 "my-sheet", 7 (records) => { 8 return records.map((r) => { 9 const email = r.get("email") as string; 10 if (!email) { 11 console.log("Email is required"); 12 r.addError("email", "Email is required"); 13 } 14 const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 15 if (email !== null && !validEmailAddress.test(email)) { 16 console.log("Invalid email address"); 17 r.addError("email", "Invalid email address"); 18 } 19 return r; 20 }); 21 }, 22 { chunkSize: 100, parallel: 2 } 23 ) 24 ); 25}
recordHook.js
1import { recordHook } from "@flatfile/plugin-record-hook"; 2 3export default async function (listener) { 4 listener.use( 5 recordHook( 6 "my-sheet", 7 (record) => { 8 const email = record.get("email") as string; 9 if (!email) { 10 console.log("Email is required"); 11 record.addError("email", "Email is required"); 12 } 13 const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 14 if (email !== null && !validEmailAddress.test(email)) { 15 console.log("Invalid email address"); 16 record.addError("email", "Invalid email address"); 17 } 18 return record; 19 } 20 ) 21 ); 22}
bulkRecordHook.ts
1import { FlatfileRecord } from "@flatfile/hooks"; 2import { bulkRecordHook } from "@flatfile/plugin-record-hook"; 3import { FlatfileListener } from "@flatfile/listener"; 4 5export default async function (listener: FlatfileListener) { 6 listener.use( 7 bulkRecordHook( 8 "contacts", 9 (records: FlatfileRecord[]) => { 10 return records.map((r) => { 11 const email = r.get("email") as string; 12 if (!email) { 13 console.log("Email is required"); 14 r.addError("email", "Email is required"); 15 } 16 const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 17 if (email !== null && !validEmailAddress.test(email)) { 18 console.log("Invalid email address"); 19 r.addError("email", "Invalid email address"); 20 } 21 return r; 22 }); 23 }, 24 { chunkSize: 100, parallel: 2 } 25 ) 26 ); 27}
recordHook.ts
1import { FlatfileRecord } from "@flatfile/hooks"; 2import { recordHook } from "@flatfile/plugin-record-hook"; 3import { FlatfileListener } from "@flatfile/listener"; 4 5export default async function (listener: FlatfileListener) { 6 listener.use( 7 recordHook( 8 "contacts", 9 (record: FlatfileRecord) => { 10 const email = record.get("email") as string; 11 if (!email) { 12 console.log("Email is required"); 13 record.addError("email", "Email is required"); 14 } 15 const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 16 if (email !== null && !validEmailAddress.test(email)) { 17 console.log("Invalid email address"); 18 record.addError("email", "Invalid email address"); 19 } 20 return record; 21 } 22 ) 23 ); 24}
No vulnerabilities found.
No security vulnerabilities found.