@baukit/notifications-core

中文文档
0.18.3发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 8160

无框架的本地通知规划:分区发生分辨率、地平线过滤、确定保存、取消和时间表集、以及平台端口上所有者范围替换.

中文使用文档
文档目录4 节
  1. 规划
  2. 拥有的替换
  3. 合规套房
  4. 边界

@baukit/notifications-core

@baukit/notifications-core 计划本地通知,只替换产品拥有的. 除此之外,它没有运行时间依赖关系 @baukit/localization-core 绝不进口 通知库。 产品决定哪些产品符合条件,以及副本的内容. 这个包把它们变成瞬间, 扔出地平线以外的, 并计算什么 保留、取消和时间表.

规划

import {
  planNotificationReplacement,
  resolveNotificationOccurrences,
} from '@baukit/notifications-core';

const resolution = resolveNotificationOccurrences({
  occurrences: [
    {
      logicalId: 'plan:2026-03-29',
      civilDate: '2026-03-29',
      civilTime: '02:30',
      contentDigest: 'v3',
    },
    {
      logicalId: 'plan:2026-03-30',
      civilDate: '2026-03-30',
      civilTime: '02:30',
      contentDigest: 'v3',
    },
  ],
  timeZone: 'Europe/Berlin',
  gap: 'shiftForward',
  fold: 'earlier',
  clock: () => Date.now(),
  horizonDays: 14,
});
// resolution.desired: both entries with epochMilliseconds and transition ('gap' for the first)

const plan = planNotificationReplacement(current, resolution.desired);
// plan.keep, plan.cancel, plan.schedule, each sorted by instant, then logical ID
  • 每起事件都会解决 resolveZonedLocalTime 从 @baukit/localization-core编辑 调用者会选择空格并折叠策略;也没有默认.
  • 地平线是今天开始的民用日期 timeZone 通过今天加 horizonDays - 1。 。 。 . resolution.firstCivilDate 财务报告和审定财务报表 resolution.lastCivilDate 报告.
  • resolution.skipped 列出出现的原因 : past (此时此刻或之前) 时钟, outside_horizon,或 nonexistent_local_time (缺额) gap: 'reject') (中文(简体) ).
  • 发生时的额外字段,如通知副本,通过 desired。 。 。 .
  • 一个条目只有在其逻辑ID,即时,和内容消化全部匹配时才保留. 文本更改 在同一文摘下,故意保留。 更改文摘或通过 { replaceAll: true },改为 替换文本.
  • 无效的输入抛出 NotificationPlanError 带有 code 在适用时 logicalId数字 : invalid_civil_date, (中文(简体) ), invalid_civil_time, (中文(简体) ), invalid_time_zone, (中文(简体) ), invalid_horizon, (中文(简体) ), invalid_clock, (中文(简体) ), invalid_logical_id, (中文(简体) ), invalid_content_digest, (中文(简体) ), invalid_instant,或 duplicate_logical_id。无效的日期即使落在地平线之外也会丢出。 一个 未知的策略抛出 RangeError时,如 resolveZonedLocalTime。 。 。 .

同样的输入和时钟给出了相同的结果,无论出现时的顺序如何. 共享 向量在 fixtures/notifications/plan-vectors-v1.json 月和年的DST缺口和折叠数 更改、区间旅行、重复、无效输入、内容改变和地平线边界. @baukit/notifications-core/vectors 出口 notificationPlanVectorChecks(fixture)检查 Vitest套房运行:每个成功案例产生预期计划,一旦计划实施,趋同, 和独立于输入顺序. examples/expo-notifications-conformance 把他们放进去 赫尔墨斯.

拥有的替换

createOwnedNotificationScheduler(platform, { pendingLimit }) 运行一个计划与 NotificationPlatform<TContent> 有四个呼叫的端口: list, (中文(简体) ), cancel, (中文(简体) ), permission,以及 schedule。 。 。 . @baukit/notifications-expo 是世博会的实施.

const outcome = await scheduler.replaceOwned({ namespace: 'reminders' }, desired);
// { status: 'complete' | 'incomplete' | 'superseded', kept, cancelled, scheduled, failures }
  • 当通知带有该命名空间的有效标记时,它属于命名空间 标识符是 baukit:<namespace>:<logicalId>. 其它一切将单独处理,包括其他 Baukit 命名空间和请求带有复制标记 .
  • 调度器一次取消一个请求,从不取消所有请求. 取消的项目 在同一运行中不重排失败 .
  • 它只有在需要安排时才检查许可. 没有许可,它仍然取消 已过时的条目 .
  • 它按即时顺序排行,然后停止 pendingLimit,计算每个待处理的请求 装置,不只是这个主人的.
  • 失败者携带代码和逻辑ID, 永远不会满足: list_failed, (中文(简体) ), cancel_failed, (中文(简体) ), permission_denied, (中文(简体) ), permission_failed, (中文(简体) ), schedule_failed, (中文(简体) ), schedule_limit失败者 结果 incomplete调用 replaceOwned 同一套装再次汇合.
  • 每个命名空间一次更换一次 当它运行时, 后呼唤这个命名空间 崩溃到最新的。 那些从未下定决心的人 superseded名称空间不等待 为了彼此。 每个设备共用一个调度器,这样就可以了.
  • 无效的命名空间( 小写字母和数字分隔由 . 或者说 -,最多为64个 字符)或无效的想要的集拒绝 NotificationPlanError 在平台之前 触动.

合规套房

@baukit/notifications-core/vitest 出口 describeOwnedNotificationSchedulerContract运行它 它需要消费者的维特安装.

import {
  InMemoryNotificationPlatform,
  createOwnedNotificationScheduler,
} from '@baukit/notifications-core';
import { describeOwnedNotificationSchedulerContract } from '@baukit/notifications-core/vitest';

describeOwnedNotificationSchedulerContract<string>((options) => {
  const platform = new InMemoryNotificationPlatform<string>();
  return {
    scheduler: createOwnedNotificationScheduler(platform, options),
    faults: platform.faults,
    content: (_logicalId, text) => text,
    addUnrelated: (identifier) => platform.addUnrelated(identifier),
    pending: () => platform.pending(),
  };
});

NotificationPlatformFaultState 持有注入的断层( 失败列表、 取消、 调度和 权限调用,被撤销的许可,被持有的列表),因此被嘲笑的本地模块可以再用.

边界

该包不选择提醒时间,安静时间,或复制,也不请求许可. 产品计算符合条件的矿点和内容摘要,在自己的UX中请求许可,以及 选择其平台的待定限制。 它计划每个呼叫一个时区.

版本与发布记录

@baukit/notifications-core 共发布 60 个版本,首次发布于 2026/09/29;过去 12 个月发布了 60 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.18.3latest2026/11/07今天
0.18.22026/11/061 天前
0.18.12026/11/062 天前
0.18.02026/11/052 天前
0.17.12026/11/034 天前
0.17.02026/11/025 天前

关于 @baukit/notifications-core 的常见问题

@baukit/notifications-core 是什么?

无框架的本地通知规划:分区发生分辨率、地平线过滤、确定保存、取消和时间表集、以及平台端口上所有者范围替换.

如何安装 @baukit/notifications-core?

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

@baukit/notifications-core 支持 TypeScript 吗?

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

@baukit/notifications-core 支持 ESM 还是 CommonJS?

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

@baukit/notifications-core 需要什么版本的 Node.js?

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

@baukit/notifications-core 可以商用吗?

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

@baukit/notifications-core 的下载量有多少?

根据 npm 官方下载统计,@baukit/notifications-core 在 2026/10/08 – 2026/11/06 这 30 天内被下载 8,160 次,日均约 272 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@baukit/notifications-core 还在维护吗?

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