@fungi.computer/almanac

中文文档
0.2.1发布于 2026/11/04MITTypeScriptES Module近 30 天下载 1.2万

Target-agnostic durable schedule core: cron cadence, occurrence identity, missed-tick and retry policy

原始使用文档
文档目录5 节
  1. Quickstart
  2. Examples
  3. Core concepts
  4. Shared backoff
  5. Maintainer checks

Almanac

Most people want Oyster to run their Apps or Shiitake to run their Agents. Almanac gives host authors a pure schedule core for cron cadences, occurrence identity and retries. The host owns storage, its timer and what a firing does.

Quickstart

Use Node 24 or later. Install the package and run its shipped example:

mkdir my-schedule
cd my-schedule
npm init -y
npm install @fungi.computer/almanac [email protected]
node node_modules/@fungi.computer/almanac/examples/next-occurrence.mjs

It prints 2026-10-11T09:00:00.000Z. During release qualification, install the supplied Almanac .tgz instead of the package name. Publication is a separate step.

The example uses the root export:

import { nextOccurrence } from "@fungi.computer/almanac";
import * as Result from "effect/Result";

const next = nextOccurrence(
  { expression: "0 9 * * *", timeZone: "UTC" },
  Date.parse("2026-10-11T08:00:00Z"),
);
if (Result.isFailure(next)) throw new Error(next.failure.message);
console.log(new Date(next.success).toISOString());

Examples

The same package works in a browser bundle. It needs standard Date and Intl time-zone support, and no Workers runtime, Node polyfills or host credentials. The packed browser proof runs this shipped example in Chromium. The packed Node consumer also checks the public types with strict NodeNext and skipLibCheck: false.

Core concepts

A schedule is a ScheduleCore record plus the host's own target fields. Transitions return a new record. Nothing starts a timer or writes storage.

  • nextOccurrence(cadence, after): the first occurrence strictly after after for a cron expression in an IANA zone (effect/Cron). A bad expression or zone is invalid; a cadence that never occurs again is exhausted.
  • occurrenceKey(schedule) is id:nextDueAt. A retried firing of the same occurrence has the same key, so the host can admit that occurrence idempotently.
  • Missed ticks coalesce. After a firing, and on resume, the next occurrence is computed from now, so a schedule that was down or paused runs once, not a backlog.
  • afterAdmitted finishes a one-shot or moves a recurring schedule on (pausing it with the reason if its cadence is exhausted). afterRefused keeps the same occurrence, records why and backs off (30 s doubling to 1 h by default). paused, resumed and cancelled are the state changes; paused and settled schedules are never due.

See the API reference for the complete root export.

Shared backoff

BackoffDelay fixes the pure (attempt, policy) => delayMs contract, reusing RetryPolicy. Attempt one (and attempts below one) uses the initial delay, bounded by the cap; later attempts double up to that cap. The caller supplies its own policy, and the calculation owns no clock, storage or retry execution. afterRefused uses this calculation after incrementing the refusal attempt.

Maintainer checks

pnpm --dir packages/almanac run test
pnpm --dir packages/almanac run lint
pnpm --dir packages/almanac run typecheck
pnpm --dir packages/almanac run build
pnpm --dir packages/almanac run docs
pnpm --dir packages/almanac run stranger
pnpm --dir packages/almanac run stranger:browser

Browser proof commands use the repository's heavy scheduler. Build cleans old output before emitting declarations. The archive ships the runtime, types, license, README, API reference and example. Maintainer tests stay in the source checkout. Licensed under MIT.

版本与发布记录

@fungi.computer/almanac 共发布 5 个版本,首次发布于 2026/10/17;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.1latest2026/11/0412 天前
0.2.02026/10/2323 天前
0.1.02026/10/1729 天前
0.0.12026/10/1730 天前
0.0.0-stage2026/10/1730 天前

关于 @fungi.computer/almanac 的常见问题

@fungi.computer/almanac 是什么?

Target-agnostic durable schedule core: cron cadence, occurrence identity, missed-tick and retry policy

如何安装 @fungi.computer/almanac?

在项目目录运行 npm install @fungi.computer/almanac,或使用 pnpm add / yarn add / bun add。

@fungi.computer/almanac 支持 TypeScript 吗?

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

@fungi.computer/almanac 支持 ESM 还是 CommonJS?

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

@fungi.computer/almanac 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fungi.computer/almanac 可以商用吗?

@fungi.computer/almanac 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fungi.computer/almanac 的下载量有多少?

根据 npm 官方下载统计,@fungi.computer/almanac 在 2026/10/16 – 2026/11/14 这 30 天内被下载 12,428 次,日均约 414 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fungi.computer/almanac 还在维护吗?

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