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

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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./rolldown-runtime-BqT_7tdF.js";
2
2
  import * as z from "zod";
3
+ import { DataHomeSource } from "@longzai-intelligence-runtime/core";
3
4
  //#region src/env.constants.d.ts
4
5
  /**
5
6
  * env 键名单一真源与缺省常量(agent-tools 范式:env 名一律 `LZI_<TOOL>_` 前缀)。
@@ -8,9 +9,9 @@ import * as z from "zod";
8
9
  * 跨机器稳定的项目事实在 lzi-npm-registry.config.ts(见 config.loader.ts)。
9
10
  */
10
11
  /**
11
- * 集中数据根 env 键(绝对路径;缺省回退仓库根同级 data/ 惯例,见 data-root.utils.ts)
12
+ * 集中数据根 env 键(绝对路径;须显式设置且路径命中,严格链正本见 architecture 仓 ADR 0113)
12
13
  */
13
- declare const ENV_KEY_DATA_ROOT = "LZI_NPM_REGISTRY_DATA_ROOT";
14
+ declare const ENV_KEY_DATA_HOME = "LZI_NPM_REGISTRY_DATA_HOME";
14
15
  /**
15
16
  * 监听地址 env 键(缺省仅本机回环——local-first 安全缺省)
16
17
  */
@@ -23,7 +24,7 @@ declare const ENV_KEY_PORT = "LZI_NPM_REGISTRY_PORT";
23
24
  * env 键名单一真源(供校验/文档/CLI 提示统一引用)
24
25
  */
25
26
  declare const ENV_KEYS: {
26
- readonly dataRoot: "LZI_NPM_REGISTRY_DATA_ROOT";
27
+ readonly dataHome: "LZI_NPM_REGISTRY_DATA_HOME";
27
28
  readonly host: "LZI_NPM_REGISTRY_HOST";
28
29
  readonly port: "LZI_NPM_REGISTRY_PORT";
29
30
  };
@@ -36,18 +37,18 @@ declare const DEFAULT_HOST = "127.0.0.1";
36
37
  */
37
38
  declare const DEFAULT_PORT = 4874;
38
39
  /**
39
- * 集中数据目录名(位于产品群 data/ 集中目录下,命名对齐 `<project-name>-data` 惯例)
40
+ * 集中数据目录名(位于产品群统一数据区下,纯项目完整名称不带后缀,ADR 0113 命名铁律)
40
41
  */
41
- declare const CENTRAL_DATA_DIR_NAME = "longzai-intelligence-npm-registry-data";
42
+ declare const CENTRAL_DATA_DIR_NAME = "longzai-intelligence-npm-registry";
42
43
  //#endregion
43
44
  //#region src/env.config.d.ts
44
45
  /**
45
- * env 契约(HOST / PORT 必填有缺省;DATA_ROOT 可空——由 resolveDataRoot 解析链兜底)
46
+ * env 契约(HOST / PORT 必填有缺省;DATA_HOME 可空——显式性校验由 resolveDataRoot 严格链承载)
46
47
  */
47
48
  declare const NpmRegistryEnvSchema: z.ZodObject<{
48
49
  host: z.ZodDefault<z.ZodString>;
49
50
  port: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
50
- dataRoot: z.ZodOptional<z.ZodString>;
51
+ dataHome: z.ZodOptional<z.ZodString>;
51
52
  }, z.core.$strip>;
52
53
  /**
53
54
  * env 形态
@@ -77,34 +78,27 @@ declare function loadEffectiveEnv(repoRoot: string | null): Record<string, strin
77
78
  declare function parseNpmRegistryEnv(source: Record<string, string | undefined>): NpmRegistryEnv;
78
79
  //#endregion
79
80
  //#region src/data-root.utils.d.ts
80
- /**
81
- * 集中数据根解析链(agent-tools hub-resolution 同款范式:显式 env > 惯例回退 > 响亮报错)。
82
- *
83
- * 惯例回退:`<repoRoot>/../../data/longzai-intelligence-npm-registry-data`
84
- * (仓库群平铺于 m5-edition 下,../.. 即产品群根,data/ 为集中数据目录)。
85
- */
86
81
  /**
87
82
  * 数据根解析结果
88
83
  */
89
84
  type ResolvedDataRoot = {
90
85
  /**
91
- * 集中数据根绝对路径(调用方负责建目录,见 core.ensureLayout)
86
+ * 集中数据根绝对路径(调用方负责建目录,见 core 的 ensureLayout)
92
87
  */
93
88
  dataRoot: string;
94
89
  /**
95
- * 命中来源:env = 环境变量/.env 显式指定;convention = 仓库根惯例回退
90
+ * 命中来源:env 为项目级显式键命中,machine 与 xdg-fallback 仅在声明 allowFallback 时出现
96
91
  */
97
- source: 'env' | 'convention';
92
+ source: DataHomeSource;
98
93
  };
99
94
  /**
100
95
  * 解析集中数据根
101
96
  *
102
- * @param envValue - env 提供的路径文本(可空;相对路径以 cwd 为基)
103
- * @param repoRoot - 仓库根(convention 回退的前提;可为 null)
97
+ * @param env - 原始环境变量键值集合,.env 与 `process.env` 合并形态
104
98
  * @returns 数据根与命中来源
105
- * @throws {@link Error} env 与惯例均无法提供时(列出全部尝试,附修复指引)
99
+ * @throws {@link DataHomeResolveError} 项目级键未设置或显式路径未命中时抛出
106
100
  */
107
- declare function resolveDataRoot(envValue: string | undefined, repoRoot: string | null): ResolvedDataRoot;
101
+ declare function resolveDataRoot(env: Record<string, string | undefined>): ResolvedDataRoot;
108
102
  //#endregion
109
103
  //#region src/npm-registry.config.d.ts
110
104
  /**
@@ -201,4 +195,4 @@ type LoadedNpmRegistryConfig = {
201
195
  */
202
196
  declare function loadNpmRegistryConfig(cwd?: string): Promise<LoadedNpmRegistryConfig>;
203
197
  //#endregion
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 };
198
+ export { CENTRAL_DATA_DIR_NAME, DEFAULT_HOST, DEFAULT_NPM_REGISTRY_CONFIG, DEFAULT_PORT, ENV_KEYS, ENV_KEY_DATA_HOME, 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
- 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}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};
1
+ import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,join as r,resolve as i}from"node:path";import*as a from"zod";import{resolveDataHome as o}from"@longzai-intelligence-runtime/core";import{loadUnifiedConfig as s}from"@longzai-intelligence-shared-config/core";const c=`LZI_NPM_REGISTRY_DATA_HOME`,l=`LZI_NPM_REGISTRY_HOST`,u=`LZI_NPM_REGISTRY_PORT`,d={dataHome:c,host:l,port:u},f=`127.0.0.1`,p=4874,m=`longzai-intelligence-npm-registry`,h=a.object({host:a.string().min(1).default(f),port:a.coerce.number().int().min(0).max(65535).default(p),dataHome:a.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 i={};if(n!==null){let a=r(n,`.env`);e(a)&&(i=g(t(a,`utf8`)))}return{...i,...process.env}}function v(e){let t=h.safeParse({host:e[d.host],port:e[d.port],dataHome:e[d.dataHome]});if(!t.success)throw Error(`[config] lzi-npm-registry env 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}const y={domain:`npm-registry`,centralDataDirName:m};function b(e){let t=o({config:y,env:e});return{dataRoot:t.dataHome,source:t.source}}const x=[`off`,`passthrough`],S=a.enum(x),C=a.strictObject({idleMs:a.number().int().nonnegative()}),w=a.strictObject({upstream:a.strictObject({registry:a.url(),mode:S}),publish:a.strictObject({allowPattern:a.string().min(1).refine(e=>{try{return new RegExp(e),!0}catch{return!1}},{error:`allowPattern 必须是合法正则源文本`})}),shutdown:C.default({idleMs:6e5})}),T={upstream:{registry:`https://mirrors.cloud.tencent.com/npm/`,mode:`passthrough`},publish:{allowPattern:`^@longzai-intelligence(-[a-z0-9-]+)?/`},shutdown:{idleMs:6e5}};function E(e){let t=w.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 D(e){return e}const O=`lzi-npm-registry.config.ts`,k=`npmRegistry`;async function A(e=process.cwd()){let t=await s({cwd:e,standaloneFile:O,unifiedField:k});return t.success?{config:E(t.config),source:t.source,repoRoot:i(n(t.configFilePath))}:{config:T,source:`builtin`,repoRoot:null}}export{m as CENTRAL_DATA_DIR_NAME,f as DEFAULT_HOST,T as DEFAULT_NPM_REGISTRY_CONFIG,p as DEFAULT_PORT,d as ENV_KEYS,c as ENV_KEY_DATA_HOME,l as ENV_KEY_HOST,u as ENV_KEY_PORT,w as NpmRegistryConfigSchema,h as NpmRegistryEnvSchema,O as STANDALONE_CONFIG_FILE,C as ShutdownSchema,k as UNIFIED_CONFIG_FIELD,x as UPSTREAM_MODES,S as UpstreamModeSchema,D as defineConfig,_ as loadEffectiveEnv,A as loadNpmRegistryConfig,g as parseEnvFileContent,E as parseNpmRegistryConfig,v as parseNpmRegistryEnv,b as resolveDataRoot};
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-npm-registry/config",
3
- "version": "0.0.5",
4
- "description": "Longzai Intelligence 本地 npm registry 配置收口:lzi-npm-registry.config.ts 契约加载 / env 单一真源 / 集中数据根解析链",
3
+ "version": "0.0.7",
4
+ "description": "Longzai Intelligence 本地 npm registry 配置",
5
+ "keywords": [
6
+ "config",
7
+ "longzai-intelligence",
8
+ "npm-registry",
9
+ "schema",
10
+ "zod"
11
+ ],
5
12
  "license": "UNLICENSED",
6
13
  "files": [
7
14
  "dist"
@@ -31,6 +38,8 @@
31
38
  "clean": "lzi-dev-cli clean"
32
39
  },
33
40
  "dependencies": {
41
+ "@longzai-intelligence-runtime/config": "^0.0.3",
42
+ "@longzai-intelligence-runtime/core": "^0.0.3",
34
43
  "@longzai-intelligence-shared-config/core": "^0.0.7",
35
44
  "zod": "^4.4.3"
36
45
  }