@useairfoil/connector-kit

中文文档
0.7.0发布于 2026/11/03TypeScriptES Module构建来源已验证

Use this package to build an Airfoil producer connector.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Running
  4. Configuration
  5. Demo data

Connector Kit

Use this package to build an Airfoil producer connector.

Install

pnpm add @useairfoil/connector-kit effect@^4

Usage

  • Connector, Resource, Fetch, and Cursor define the data flow.
  • Manifest defines user config.
  • ConnectorApp checks config and runs the HTTP server.
  • Webhook defines webhook routes.
  • Ingestor writes batches to the console or Iceberg.
  • StateStore keeps ingestion progress.

Here is a small resource:

import { Connector, Cursor, Fetch, Iceberg, Resource } from "@useairfoil/connector-kit";
import { Effect, Schema } from "effect";

const PostSchema = Schema.Struct({
  id: Schema.String.pipe(Iceberg.field(1)),
  updatedAt: Schema.String.pipe(Iceberg.field(2)),
}).pipe(Iceberg.identifier("id"));

const Posts = Resource.entity({
  name: "posts",
  rowSchema: PostSchema,
  version: "updatedAt",

  check: Effect.void,
  backfill: Fetch.page({
    pageCursor: Cursor.number(),
    cutoff: Cursor.isoDateTime(),
    fetch: () =>
      Effect.succeed({
        rows: [],
        nextPageCursor: 1,
        hasMore: false,
      }),
  }),
});

const connector = Connector.define({
  name: "producer-example",
  resources: [Posts],
});

When one provider log covers several resources, such as an events API, give the connector a single changes feed instead of changes on each resource. The feed reads the log once per run and returns rows by resource name:

const connector = Connector.define({
  name: "producer-example",
  resources: [Posts, Comments],
  changes: Fetch.feed({
    resources: [Posts, Comments],
    cursor: Cursor.string(),
    interval: "5 minutes",
    fetch: ({ cursor }) =>
      readEvents(cursor).pipe(
        Effect.map((page) => ({
          rows: { posts: page.posts, comments: page.comments },
          cursor: page.next,
          // Runs again without waiting for the interval.
          hasMore: page.hasMore,
        })),
      ),
  }),
});

A resource's own changes can return hasMore the same way, to split a long read across runs.

Each resource in the feed stores the feed cursor, so status shows it per resource. A resource in the feed cannot also define its own changes.

The Airfoil Storage Engine supports upsert operations on Iceberg rows. Use the Iceberg.identifier helper to annotate identifier rows (primary keys). This annotation must always be used last.

Upsert operations replace the full row conten, for this reason the change feed must include all fields. If the webhook events don't include all fields, the implementation must fetch the resource before pushing it into the engine.

The Airfoil Storage Engine implements soft deletions. To delete a row, push only the key, version column (if any), _deleted = true and any other required column. If the target service supports restoring records, the connector must send _deleted = false with every row.

Running

When testing locally, you can run the connector in memory:

  • StateStore.layerMemory: stores the connector's state in memory.
  • Ingestor.layerConsole: outputs new batches to console.

For a durable run:

  • RuntimeConfig.layerHosted(): loads the configuration from a file.
  • StateStore.layerSql(): stores the connector's state in PostgreSQL.
  • Ingestor.layerArrowFlightConfig(connector): publish data to Apache Iceberg using the Airfoil Storage Engine and Arrow Flight.

The built-in HTTP server has /health, /status, and /metrics endpoints.

Configuration

VariableRequiredDefault
AIRFOIL_CONFIG_PATHyesnone
ENGINE_URIyesnone
AIRFOIL_CATALOGyesnone
AIRFOIL_TABLE_BINDINGSyesnone
AIRFOIL_CONNECTOR_INSTANCE_IDyesnone
POSTGRES_CONNECTION_STRINGyesnone
AIRFOIL_HTTP_PORTno8080
AIRFOIL_STATE_TABLEno_airfoil_connectors_state

The AIRFOIL_TABLE_BINDINGS environment variables controls which resources are synced and the target table. At least one resource must be defined.

AIRFOIL_TABLE_BINDINGS={"posts":{"namespace":["default"],"name":"posts"}}

Use only lowercase letters, numbers, and underscores in table names. S3 Tables catalogs reject other characters, such as -.

Demo data

A connector with a demo has a demo command. It writes made-up rows to the bound tables, then exits. It needs no provider credentials and no PostgreSQL state.

producer-stripe demo --size 128MiB --seed 42
  • --size is the uncompressed Arrow size to write, such as 512KiB, 128MiB, or 1GiB. The run can go over by one chunk of groups, about 1 MiB with the current connectors.
  • --seed picks the data. Dates depend on when the run starts, so two runs with the same seed match only if they start at the same time and bind the same tables.
  • Setup tables, written once, such as a product catalog, don't grow. If only those are bound, the run writes them once and stops below the size. Demos with limited history, such as daily reports, also stop when they run out.
  • It needs AIRFOIL_CONFIG_PATH, ENGINE_URI, AIRFOIL_CATALOG, and AIRFOIL_TABLE_BINDINGS. An empty {} config file is enough.

A demo lists its setup and group tables and builds their rows with Demo.define. Build keys from the group index, so they are unique and other rows can point to them. Required fields a row leaves out get placeholder values from the row schema. Every row is checked against its row schema before it's written.

版本与发布记录

@useairfoil/connector-kit 共发布 9 个版本,首次发布于 2026/03/10;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/03今天
0.6.12026/10/295 天前
0.6.02026/08/252 个月前
0.5.32026/08/142 个月前
0.5.22026/08/142 个月前
0.5.12026/08/142 个月前

关于 @useairfoil/connector-kit 的常见问题

@useairfoil/connector-kit 是什么?

使用这个包来建立一个翼型生产者连接器。

如何安装 @useairfoil/connector-kit?

在项目目录运行 npm install @useairfoil/connector-kit,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:effect(^4.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@useairfoil/connector-kit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@useairfoil/connector-kit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@useairfoil/connector-kit 可以商用吗?

@useairfoil/connector-kit 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@useairfoil/connector-kit 还在维护吗?

最新版本 0.7.0 发布于 2026/11/03(今天);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/03/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。