npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@masthead-data/dataform-plugin

v0.0.2

Published

Masthead Data plugin for Dataform to optimize BigQuery resource usage

Readme

Masthead Plugin for Dataform

Overview

This plugin is designed to optimize BigQuery resource usage by automatically assigning compute reservations to Dataform actions based on predefined configuration. This system enables businesses to efficiently manage their BigQuery costs and resource allocation with minimal manual intervention.

Key Benefits

  • Cost optimization: Automatically route high-priority workloads to reserved slots and low-priority workloads to on-demand pricing
  • Resource efficiency: Ensure critical data pipelines get guaranteed compute resources while non-critical tasks use flexible pricing
  • Automated re-assignement: Once configured, reservations are applied automatically based on action categorization
  • Flexible configuration: Easy adjustment of reservation policies through configuration updates

Getting Started

Initial Setup

Add the dependency to your package.json:

{
  "dependencies": {
    "@masthead-data/dataform-plugin": "0.0.2"
  }
}

and click Install Packages in Dataform UI.

Then, import the plugin and create a setter function in your global scope under /includes directory:

const reservations = require("@masthead-data/dataform-plugin");

const RESERVATION_CONFIG = [
  ...
];

const reservation_setter = reservations.createReservationSetter(RESERVATION_CONFIG);

module.exports = {
  ...
  reservation_setter
}

Configuration Structure

Configuration object defining reservation policies:

const RESERVATION_CONFIG = [
  {
    tag: 'high_slots',
    reservation: 'projects/{project}/locations/{location}/reservations/{name}',
    actions: [
      'project.dataset.table'
    ]
  },
  {
    tag: 'low_slots',
    reservation: null,
    actions: []
  },
  {
    tag: 'on_demand',
    reservation: 'none',
    actions: [
      'project.action_name'
    ]
  }
]

Configuration arguments:

  • tag: Human-readable identifier for the reservation category
  • reservation: BigQuery reservation resource name:
    • Full path: projects/{project}/locations/{location}/reservations/{name}
    • 'none': for on-demand pricing
    • null: Use a default reservation
  • actions: Array of Dataform action names that are assigned to the reservation

Usage examples

publish actions

  • SQLX templates:
config {
  type: "table",
  schema: "my_schema",
}

pre_operations {
  ${reservations.reservation_setter(ctx)}
}

SELECT * FROM source_table
  • JavaScript templates:
publish('my_table', {
    type: 'table',
    schema: 'my_schema',
}).preOps(ctx => `
${reservations.reservation_setter(ctx)}
`).query(ctx => `
SELECT * FROM source_table
`);

operate actions

  • SQLX templates:
config {
  type: "operations",
}

${reservations.reservation_setter(ctx)}

MERGE target_table T
USING source_table S
ON T.id = S.id
WHEN MATCHED THEN UPDATE SET value = S.value
WHEN NOT MATCHED THEN INSERT (id, value) VALUES (S.id, S.value);
  • JavaScript templates:
operate('my_merge_operation', {
  hasOutput: true,
}).queries(ctx => `
${reservations.reservation_setter(ctx)}

MERGE target_table T
USING source_table S
ON T.id = S.id
WHEN MATCHED THEN UPDATE SET value = S.value
WHEN NOT MATCHED THEN INSERT (id, value) VALUES (S.id, S.value);
`);

Example implementation can be found in https://github.com/HTTPArchive/dataform.

Under the Hood

Action Name Detection

The plugin detects the action using two methods:

  • Primary: ctx.self() function (for most Dataform contexts)
  • Fallback: ctx.operation.proto.target (for operation contexts)

Reservation Lookup

Actions are matched against the RESERVATION_CONFIG using exact string matching. The first matching reservation is applied. If no match is found, the default reservation (first entry with null reservation) is used. If no default is defined, no reservation override is applied.

SQL Generation

Based on the matched reservation, the system generates appropriate SQL:

  • Specific Reservation: SET @@reservation='projects/{project}/locations/{location}/reservations/{name}';
  • On-demand: SET @@reservation='none';
  • Default/Null: Empty string (no reservation override)