Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
[WARNING: This package is still very alpha. This mesasage will be removed when this thing is actually kinda ready for real work.]
Duality is a framework for writing and running data transformation pipelines. Pipelines are built from components that use the Node.js Streams system to move data down the pipeline, enriching or transforming it as it goes.
Duality makes it easy to create, run, and manage pipeline scripts. It offers sensible conventions to make it easy to manage and maintain a large library of scripts.
This simple pipeline queries contact records from a database, and splits each record into separate 'person' and 'company' records, then inserts the results into a second database.
p = new Pipeline();
p.use(new database.Query('select * from contacts'));
p.use(function(contact) {
var companyId = GUID();
return [
{
_headers: {type: 'person'},
email: contact.email,
name: contact.firstname + ' ' + contact.lastname
company_id: companyId
},
{
_headers: {type: 'company'},
name: contact.compnay_name,
guid: companyId
}
]
});
p.use(util.Logger());
p.use(new database.insert(null, 'database1'));
p.run()
Duality pipelines operate in objectMode, passing discrete JS objects as messsages. Objects
can use any format. By convention objects may contain a key _headers
which holds a dictionary
of metadata to describe the message.
Components are the basic unit of logic in a pipeline. Components can either generate
new messages, transform existing messages, or write messages to some output. Duality
includes a set of standard components, and makes it very easy to create new ad-hoc
components from simple functions. It's also possible to construct new re-usuable
components by subclassing the standard classes in the Node stream
package.
To create an ad-hoc component, simply pass a function to the use
method on a
Pipeline. Synchronous functions are passed each message in the pipeline, and the
return value from the function is passed on down the pipeline:
p.use(function(msg, context) {
msg.newkey = 'newvalue';
return msg;
});
If you need to return results asynchronously just define your function to take a callback second argument:
p.use(function(msg, context, callback) {
resource.get(function(rows) {
rows.forEach(function(row) {
callback(row, true);
});
callback(null);
});
});
Invoke the callback with output messages and pass true
as the second argument
until there are no more messages to generate.
context
The context
is a global object available in the pipeline. It is typically used
to pass configuration data into a component. The configuration for the pipeline
is passed to the pipeline constructor, and becomes available under the config
key in the context:
p = new Pipeline('test max', {max:10});
p.use(function(msg, context) {
console.log("Max is: ", context.config.max); <-- prints: Max is 10
});
Components may add data to the context in order to share that data with other
components. For example, the database.Connection
components adds the database
connection object to the context.
Any pipeline can be executed by calling run
:
p = new Pipeline();
...
p.run();
This works for ad-hoc scripts, but Duality includes support for multiple types
of triggers. Triggers activate the pipeline, and may supply
0 or more initial messages. The timer
trigger can run a pipeline on an
interval. The http_get
and http_post
triggers are activated
by HTTP calls and will provide their inputs as message(s) to the pipeline.
FAQs
Simple ETL stream toolkit
We found that duality demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.