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

@notion-headless-cms/core

v0.3.17

Published

Core CMS engine for notion-headless-cms — fetch, transform, cache with stale-while-revalidate strategy

Readme

@notion-headless-cms/core

CMS エンジン本体。createCMS を提供し、SWR / 更新検知 / フック / リトライ / Web Standard Route Handler を内蔵する。外部ランタイム依存ゼロ

インストール

pnpm add @notion-headless-cms/core @notion-headless-cms/notion-orm \
  @notion-headless-cms/renderer @notionhq/client zod \
  unified remark-parse remark-gfm remark-rehype rehype-stringify

core 自体は依存ゼロだが、実際に Notion を叩くには notion-orm、 HTML 化には renderer が必要。CLI 生成物 (nhc-schema.ts) が notion-orm を自動参照する。

基本形

import { createCMS, nodePreset } from "@notion-headless-cms/core";
import { cmsDataSources } from "./generated/nhc-schema";

const cms = createCMS({
  ...nodePreset({ ttlMs: 5 * 60_000 }),
  dataSources: cmsDataSources,
});

const posts = await cms.posts.getList();
const post = await cms.posts.getItem("my-post");
if (post) console.log(await post.content.html());

公開 API

createCMS(opts)

  • dataSources: CLI が生成する cmsDataSources (必須)
  • cache?: CacheConfig | "disabled"
  • renderer?: RendererFn (未指定なら @notion-headless-cms/renderer を動的ロード)
  • content?: imageProxyBase
  • waitUntil?: Cloudflare Workers の ctx.waitUntil
  • hooks? / plugins? / logger? / rateLimiter?

nodePreset(opts?)

Node.js 向けプリセット。{ cache: { document: memoryDocumentCache, image: memoryImageCache }, renderer } を返す。

  • cache?: CacheConfig | "disabled" — デフォルトは memory cache
  • ttlMs?: SWR TTL (ミリ秒)
  • renderer?: カスタム renderer

BaseContentItem — 全コンテンツの基本型

CLI 生成の createCMS ラッパーで返される items は、スキーマで定義されたプロパティに加えて以下の自動フィールドを含む:

  • id: string — Notion ページ ID
  • slug: string — コレクション設定の fields.slug で指定したプロパティから抽出
  • title?: string | null — Notion title 型プロパティ(自動検出)
  • updatedAt: string — Notion ページの最終編集時刻(ISO-8601、キャッシュ更新判定に使用)
  • lastEditedTime?: string — Notion の page.last_edited_time と同値。常にセットされるシステムフィールド(updatedAt と同じ値)
  • status?: string | nullfields.status で指定したプロパティ
  • publishedAt?: string | nullfields.publishedAt で指定したプロパティ

cms.<collection> の主なメソッド

  • getItem(slug) — 本文込みで単件取得 (SWR)。返り値は T & { content: { blocks, html(), markdown() } }
  • getList(opts?) — 公開済み一覧 (本文なし)
  • getStaticParams() / getStaticPaths() — SSG 用
  • adjacent(slug, opts?) — 前後記事ナビゲーション
  • revalidate(scope?) / prefetch(opts?) — コレクション別キャッシュ操作

グローバル操作

  • cms.$collections — コレクション名一覧
  • cms.$revalidate(scope?)"all" | { collection } | { collection, slug }
  • cms.$handler(opts?) — Web Standard (req) => Response を返す (画像プロキシ + webhook)
  • cms.$getCachedImage(hash) — 画像キャッシュ直アクセス
  • cms.cacheImage(url) — Notion 画像 URL を {imageProxyBase}/{sha256} 形式に変換しキャッシュへ書き込む。画像キャッシュ未設定なら undefined@notion-headless-cms/react-renderer/serverresolveBlockImageUrls などサーバー側で URL 書き換えに使う
  • cms.imageProxyBase — 画像プロキシのベース URL (createCMS({ imageProxyBase })、デフォルト /api/images)

cache アダプタ

  • memoryDocumentCache({ maxItems? }) — LRU 対応インメモリキャッシュ
  • memoryImageCache({ maxItems?, maxSizeBytes? })
  • noopDocumentCache() / noopImageCache()

エラー

  • CMSError / isCMSError / isCMSErrorInNamespace(err, "core/")
  • 名前空間: core/* / source/* / cache/* / renderer/* / cli/*

サブパスエクスポート

import { CMSError } from "@notion-headless-cms/core/errors";
import { memoryDocumentCache } from "@notion-headless-cms/core/cache/memory";

| サブパス | 内容 | |---|---| | @notion-headless-cms/core | 全エクスポート | | @notion-headless-cms/core/errors | CMSError / isCMSError / isCMSErrorInNamespace | | @notion-headless-cms/core/hooks | mergeHooks / mergeLoggers | | @notion-headless-cms/core/cache/memory | memoryDocumentCache / memoryImageCache | | @notion-headless-cms/core/cache/noop | noopDocumentCache / noopImageCache |

ランタイム別レシピ

詳細ドキュメント