@longzai-intelligence-npm-registry/config 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @longzai-intelligence-npm-registry/config
2
+
3
+ `@longzai-intelligence-npm-registry/config` 是 Longzai Intelligence Npm Registry 的配置包,为仓内服务与命令行提供项目配置契约、env 契约与集中数据根解析能力。
4
+
5
+ ## 简介
6
+
7
+ 治理 registry 运行配置的单一真源:跨机器稳定的项目事实(上游 registry 与直通模式、publish scope 守卫)定于仓级配置契约,机器本地数据(集中数据根、监听地址与端口)只走 env——约束两层不混写、项目事实零路径可入 git,数据根在显式 env 与惯例回退之间有确定解析次序。
8
+
9
+ ## 能力
10
+
11
+ - 仓级配置契约与装载(standalone / unified / 内置缺省三序回退)
12
+ - env 契约与有效 env 合成(.env 显式兜底读取,进程环境优先)
13
+ - 集中数据根解析链(显式 env > 惯例回退 > 响亮报错)
14
+ - 上游直通模式枚举、env 键名与缺省监听参数的常量真源
package/dist/index.d.ts CHANGED
@@ -158,6 +158,13 @@ declare const DEFAULT_NPM_REGISTRY_CONFIG: NpmRegistryConfig;
158
158
  * @throws {@link Error} 配置形状或取值不合法时(响亮失败并逐键列出原因)
159
159
  */
160
160
  declare function parseNpmRegistryConfig(source: unknown): NpmRegistryConfig;
161
+ /**
162
+ * 配置工厂:类型收口 + 便于 IDE 推导(全局 ADR 0097 决策 2 defineXXX 收口)
163
+ *
164
+ * @param config - 就地配置对象
165
+ * @returns 原样返回的配置对象(运行时校验由加载方执行)
166
+ */
167
+ declare function defineConfig(config: NpmRegistryConfig): NpmRegistryConfig;
161
168
  //#endregion
162
169
  //#region src/config.loader.d.ts
163
170
  /**
@@ -194,4 +201,4 @@ type LoadedNpmRegistryConfig = {
194
201
  */
195
202
  declare function loadNpmRegistryConfig(cwd?: string): Promise<LoadedNpmRegistryConfig>;
196
203
  //#endregion
197
- export { CENTRAL_DATA_DIR_NAME, DEFAULT_HOST, DEFAULT_NPM_REGISTRY_CONFIG, DEFAULT_PORT, ENV_KEYS, ENV_KEY_DATA_ROOT, ENV_KEY_HOST, ENV_KEY_PORT, type LoadedNpmRegistryConfig, type NpmRegistryConfig, NpmRegistryConfigSchema, type NpmRegistryEnv, NpmRegistryEnvSchema, type ResolvedDataRoot, STANDALONE_CONFIG_FILE, ShutdownSchema, UNIFIED_CONFIG_FIELD, UPSTREAM_MODES, UpstreamModeSchema, loadEffectiveEnv, loadNpmRegistryConfig, parseEnvFileContent, parseNpmRegistryConfig, parseNpmRegistryEnv, resolveDataRoot };
204
+ export { CENTRAL_DATA_DIR_NAME, DEFAULT_HOST, DEFAULT_NPM_REGISTRY_CONFIG, DEFAULT_PORT, ENV_KEYS, ENV_KEY_DATA_ROOT, ENV_KEY_HOST, ENV_KEY_PORT, type LoadedNpmRegistryConfig, type NpmRegistryConfig, NpmRegistryConfigSchema, type NpmRegistryEnv, NpmRegistryEnvSchema, type ResolvedDataRoot, STANDALONE_CONFIG_FILE, ShutdownSchema, UNIFIED_CONFIG_FIELD, UPSTREAM_MODES, UpstreamModeSchema, defineConfig, loadEffectiveEnv, loadNpmRegistryConfig, parseEnvFileContent, parseNpmRegistryConfig, parseNpmRegistryEnv, resolveDataRoot };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,isAbsolute as r,join as i,resolve as a}from"node:path";import*as o from"zod";import{loadUnifiedConfig as s}from"@longzai-intelligence-shared-config/core";const c=`LZI_NPM_REGISTRY_DATA_ROOT`,l=`LZI_NPM_REGISTRY_HOST`,u=`LZI_NPM_REGISTRY_PORT`,d={dataRoot:c,host:l,port:u},f=`127.0.0.1`,p=4874,m=`longzai-intelligence-npm-registry-data`,h=o.object({host:o.string().min(1).default(f),port:o.coerce.number().int().min(0).max(65535).default(p),dataRoot:o.string().min(1).optional()});function g(e){let t={};for(let n of e.split(`
2
- `)){let e=n.trim();if(e===``||e.startsWith(`#`))continue;let r=e.indexOf(`=`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)&&a.length>=2||a.startsWith(`'`)&&a.endsWith(`'`)&&a.length>=2)&&(a=a.slice(1,-1)),t[i]=a}return t}function _(n){let r={};if(n!==null){let a=i(n,`.env`);e(a)&&(r=g(t(a,`utf8`)))}return{...r,...process.env}}function v(e){let t=h.safeParse({host:e[d.host],port:e[d.port],dataRoot:e[d.dataRoot]});if(!t.success)throw Error(`[config] lzi-npm-registry env 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}function y(e,t){if(e!==void 0&&e!==``)return{dataRoot:r(e)?e:a(process.cwd(),e),source:`env`};if(t!==null)return{dataRoot:a(t,`../../data`,m),source:`convention`};throw Error(`[config] 无法解析集中数据根(尝试:1) ${d.dataRoot} 环境变量/.env;2) 仓库根 ../../data/${m} 惯例回退,但未找到 lzi-npm-registry.config.ts 无法推导仓库根)。修复:在仓库根运行 \`bun run init\` 固化 .env,或显式设置 ${d.dataRoot}。`)}const b=[`off`,`passthrough`],x=o.enum(b),S=o.strictObject({idleMs:o.number().int().nonnegative()}),C=o.strictObject({upstream:o.strictObject({registry:o.url(),mode:x}),publish:o.strictObject({allowPattern:o.string().min(1).refine(e=>{try{return new RegExp(e),!0}catch{return!1}},{error:`allowPattern 必须是合法正则源文本`})}),shutdown:S.default({idleMs:0})}),w={upstream:{registry:`https://mirrors.cloud.tencent.com/npm/`,mode:`passthrough`},publish:{allowPattern:`^@longzai-intelligence(-[a-z0-9-]+)?/`},shutdown:{idleMs:0}};function T(e){let t=C.safeParse(e);if(!t.success)throw Error(`[config] lzi-npm-registry.config.ts 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}const E=`lzi-npm-registry.config.ts`,D=`npmRegistry`;async function O(e=process.cwd()){let t=await s({cwd:e,standaloneFile:E,unifiedField:D});return t.success?{config:T(t.config),source:t.source,repoRoot:a(n(t.configFilePath))}:{config:w,source:`builtin`,repoRoot:null}}export{m as CENTRAL_DATA_DIR_NAME,f as DEFAULT_HOST,w as DEFAULT_NPM_REGISTRY_CONFIG,p as DEFAULT_PORT,d as ENV_KEYS,c as ENV_KEY_DATA_ROOT,l as ENV_KEY_HOST,u as ENV_KEY_PORT,C as NpmRegistryConfigSchema,h as NpmRegistryEnvSchema,E as STANDALONE_CONFIG_FILE,S as ShutdownSchema,D as UNIFIED_CONFIG_FIELD,b as UPSTREAM_MODES,x as UpstreamModeSchema,_ as loadEffectiveEnv,O as loadNpmRegistryConfig,g as parseEnvFileContent,T as parseNpmRegistryConfig,v as parseNpmRegistryEnv,y as resolveDataRoot};
2
+ `)){let e=n.trim();if(e===``||e.startsWith(`#`))continue;let r=e.indexOf(`=`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)&&a.length>=2||a.startsWith(`'`)&&a.endsWith(`'`)&&a.length>=2)&&(a=a.slice(1,-1)),t[i]=a}return t}function _(n){let r={};if(n!==null){let a=i(n,`.env`);e(a)&&(r=g(t(a,`utf8`)))}return{...r,...process.env}}function v(e){let t=h.safeParse({host:e[d.host],port:e[d.port],dataRoot:e[d.dataRoot]});if(!t.success)throw Error(`[config] lzi-npm-registry env 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}function y(e,t){if(e!==void 0&&e!==``)return{dataRoot:r(e)?e:a(process.cwd(),e),source:`env`};if(t!==null)return{dataRoot:a(t,`../../data`,m),source:`convention`};throw Error(`[config] 无法解析集中数据根(尝试:1) ${d.dataRoot} 环境变量/.env;2) 仓库根 ../../data/${m} 惯例回退,但未找到 lzi-npm-registry.config.ts 无法推导仓库根)。修复:在仓库根运行 \`bun run init\` 固化 .env,或显式设置 ${d.dataRoot}。`)}const b=[`off`,`passthrough`],x=o.enum(b),S=o.strictObject({idleMs:o.number().int().nonnegative()}),C=o.strictObject({upstream:o.strictObject({registry:o.url(),mode:x}),publish:o.strictObject({allowPattern:o.string().min(1).refine(e=>{try{return new RegExp(e),!0}catch{return!1}},{error:`allowPattern 必须是合法正则源文本`})}),shutdown:S.default({idleMs:0})}),w={upstream:{registry:`https://mirrors.cloud.tencent.com/npm/`,mode:`passthrough`},publish:{allowPattern:`^@longzai-intelligence(-[a-z0-9-]+)?/`},shutdown:{idleMs:0}};function T(e){let t=C.safeParse(e);if(!t.success)throw Error(`[config] lzi-npm-registry.config.ts 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}function E(e){return e}const D=`lzi-npm-registry.config.ts`,O=`npmRegistry`;async function k(e=process.cwd()){let t=await s({cwd:e,standaloneFile:D,unifiedField:O});return t.success?{config:T(t.config),source:t.source,repoRoot:a(n(t.configFilePath))}:{config:w,source:`builtin`,repoRoot:null}}export{m as CENTRAL_DATA_DIR_NAME,f as DEFAULT_HOST,w as DEFAULT_NPM_REGISTRY_CONFIG,p as DEFAULT_PORT,d as ENV_KEYS,c as ENV_KEY_DATA_ROOT,l as ENV_KEY_HOST,u as ENV_KEY_PORT,C as NpmRegistryConfigSchema,h as NpmRegistryEnvSchema,D as STANDALONE_CONFIG_FILE,S as ShutdownSchema,O as UNIFIED_CONFIG_FIELD,b as UPSTREAM_MODES,x as UpstreamModeSchema,E as defineConfig,_ as loadEffectiveEnv,k as loadNpmRegistryConfig,g as parseEnvFileContent,T as parseNpmRegistryConfig,v as parseNpmRegistryEnv,y as resolveDataRoot};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-npm-registry/config",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Longzai Intelligence 本地 npm registry 配置收口:lzi-npm-registry.config.ts 契约加载 / env 单一真源 / 集中数据根解析链",
5
5
  "license": "UNLICENSED",
6
6
  "files": [