@docupace/ihub-config

中文文档
1.1.37发布于 2026/11/11ISCTypeScriptES Module近 30 天下载 2621

Reusable config GraphQL extension and standalone server

原始使用文档
文档目录6 节
  1. Run locally
  2. Use as an extension in another server
  3. configInjectorResolvers
  4. providers
  5. resolvers
  6. Environment variables

@docupace/ihub-config

Reusable GraphQL config extension and standalone server extracted from the Docupace GraphQL server.

Run locally

pnpm install

To run the package as a standalone GraphQL server, copy .env.example to .env, fill in the required values, and start the dev server:

cp .env.example .env
pnpm start:dev

The standalone server listens on http://localhost:4000/api/graphql.

Use as an extension in another server

import { getConfigExtension } from '@docupace/ihub-config';

Then add the returned extension to the host server's extensions array:

const configExtension = await getConfigExtension();

const serverInfo: ServerConfig = {
  instanceConfig: instanceConfig,
  extensions: [docupaceExtension, configExtension],
  port: 4000,
  createContext,
};

Extend the config extension with domain-specific providers, resolvers, etc.

import { getConfigExtension } from '@docupace/ihub-config';
import {
  DashboardPageConfigProvider,
  TablePageConfigProvider,
  AnyPageConfigProvider,
  DetailsPageConfigProvider,
} from './your-host-config-providers.js';
import { configResolvers } from './your-host-config-resolvers.js';

const APPLICATION_PREFERENCE_PREFIX = 'applicationPreference';

const applicationPreferenceResolver = async (keys, context) => {
  const data = await loadApplicationPreferences(keys, context);

  const result: Record<string, string | undefined> = {};
  keys.forEach((key) => (result[key] = undefined));
  data.records.forEach((record: { name: string; value: string }) => {
    result[record.name] = record.value;
  });

  return result;
};

const configExtension = await getConfigExtension({
  configInjectorResolvers: {
    [APPLICATION_PREFERENCE_PREFIX]: applicationPreferenceResolver,
  },
  providers: {
    DashboardPage: DashboardPageConfigProvider,
    TablePage: TablePageConfigProvider,
    AnyPage: AnyPageConfigProvider,
    DetailsPage: DetailsPageConfigProvider,
  },
  resolvers: configResolvers,
});

configInjectorResolvers

Use configInjectorResolvers to resolve template expressions embedded in config values, for example:

$${applicationPreference:timezone}

Each key in configInjectorResolvers is a template prefix, and each value is an async resolver function with this shape:

type ResolverFunction = (
  keys: string[],
  context: any,
) => Promise<Record<string, any>>;

When config processing encounters $${prefix:key}, it looks up the resolver for that prefix, batches the requested keys, and replaces the template with the resolved value. This is the right place to connect host-specific data sources such as application preferences, tenant settings, or user-scoped values.

providers

Use providers to register config processors by __typename. A provider runs after nested config values have been loaded and template expressions have been resolved, and can reshape or enrich the final config object before it is returned.

providers: {
  DashboardPage: DashboardPageConfigProvider,
  TablePage: TablePageConfigProvider,
  AnyPage: AnyPageConfigProvider,
  DetailsPage: DetailsPageConfigProvider,
}

Each provider must be a class with a processConfig method:

interface ConfigProvider {
  processConfig(config: any, configService: ConfigService, context: any): any;
}

This is useful for page-specific post-processing such as normalizing fragments, rewriting references, or deriving extra fields for a particular page type. Built-in providers are preserved and host providers are merged in on top.

resolvers

Use resolvers to extend the GraphQL API exposed by the config extension. Resolvers are provided as factories so they can receive the initialized configService instance:

const configResolvers = {
  query: ({ configService }) => ({
    pages: () => ({
      myCustomPage: async (obj: { path: string }, context: any) => {
        return await configService.getDirectConfig(obj.path, context);
      },
    }),
  }),
  mutation: ({ configService }) => ({
    pages: () => ({
      refreshCustomConfig: async () => {
        await configService.init();
        return true;
      },
    }),
  }),
};

Host query and mutation resolvers are deep-merged with the built-in config resolvers, so you can add new fields without re-declaring the entire resolver tree. If the same field exists in both places, the host resolver wins.

If you want to pass config stores programmatically instead of through environment variables, getConfigExtension also accepts configStores (usually used for tests only).

Environment variables

Config stores are discovered from environment variables grouped by prefix such as STANDARD or SITE:

  • <PREFIX>_CONFIG_LOCAL_PATH
  • <PREFIX>_CONFIG_REMOTE_PATH
  • <PREFIX>_CONFIG_REMOTE_BRANCH
  • <PREFIX>_CONFIG_PRIORITY
  • <PREFIX>_CONFIG_NAME

<PREFIX>_CONFIG_PRIORITY is required for every configured store.

CONFIG_LOCAL_PATH_ROOT can be used as a fallback base path when <PREFIX>_CONFIG_LOCAL_PATH is omitted, but the store still needs enough configuration to be discovered.

版本与发布记录

@docupace/ihub-config 共发布 85 个版本,首次发布于 2026/02/23;过去 12 个月发布了 85 个版本。

版本发布日期距今
1.1.37latest2026/11/112 天前
1.1.38-alpha.02026/11/103 天前
1.1.31-rel32.0rel322026/11/094 天前
1.1.31-patch.1patch2026/11/094 天前
1.1.362026/10/2915 天前
1.1.352026/10/2816 天前

其他发布通道:schwab → 1.1.18-schwab.0,edit → 1.1.27-edit.0,sync → 1.1.27-sync.0,admin → 1.1.30-admin.0,patch → 1.1.31-patch.1,rel32 → 1.1.31-rel32.0。

关于 @docupace/ihub-config 的常见问题

@docupace/ihub-config 是什么?

Reusable config GraphQL extension and standalone server

如何安装 @docupace/ihub-config?

在项目目录运行 npm install @docupace/ihub-config,或使用 pnpm add / yarn add / bun add。

@docupace/ihub-config 支持 TypeScript 吗?

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

@docupace/ihub-config 支持 ESM 还是 CommonJS?

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

@docupace/ihub-config 可以商用吗?

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

@docupace/ihub-config 的下载量有多少?

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

@docupace/ihub-config 还在维护吗?

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