@dsh-plus/web-cache-headers 0.1.0 → 0.1.1

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/lib/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
+ import { UnwrapVolatile } from "@dsh-plus/shared";
1
2
  import z from "@deepseek-ai/schemastery";
2
3
  import { Context } from "@deepseek-ai/cordis";
3
4
  //#region src/config.d.ts
4
- declare const Config: z<Schemastery.ObjectS<{
5
- enabled: z<boolean, boolean>;
6
- }>, Schemastery.ObjectT<{
7
- enabled: z<boolean, boolean>;
8
- }>>;
9
- type WebCacheHeadersConfig = Schemastery.TypeT<typeof Config>;
5
+ declare const Config: z<Schemastery.ObjectS<NoInfer<{
6
+ enabled: z<boolean, boolean, "volatile-defined">;
7
+ }>>, Schemastery.ObjectT<NoInfer<{
8
+ enabled: z<boolean, boolean, "volatile-defined">;
9
+ }>>, "plain">;
10
+ /** 活动字段形态(0.1.7 loader 解析产物:volatile 字段为活动引用)。 */
11
+ type WebCacheHeadersConfigFields = Schemastery.TypeT<typeof Config>;
12
+ /** 平面配置形态(消费面的读取形态,由活动引用解包得到)。 */
13
+ type WebCacheHeadersConfig = UnwrapVolatile<WebCacheHeadersConfigFields>;
10
14
  //#endregion
11
15
  //#region src/ns.d.ts
12
16
  /**
@@ -20,12 +24,12 @@ declare const SETTINGS_NS = "dsh-plus-web-cache-headers";
20
24
  //#region src/index.d.ts
21
25
  declare const name = "dsh-plus-web-cache-headers";
22
26
  /**
23
- * 装配补丁并接线配置源:settings 用户层($DSH_HOME/settings.yaml,热生效)
24
- * 优先,缺席/detach 回落 cordis 行级 config。enabled 翻转即时装/卸补丁,
25
- * 无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
26
- * @param ctx - 宿主上下文(settings 可选)。
27
- * @param config - 行级 config(settings 缺席时的默认值来源)。
27
+ * 装配补丁并接线配置源:0.1.7 起配置为 loader 解析的 volatile 活动字段
28
+ * (用户层 override 并入行级 config,写入原位提交),enabled 翻转即时装/卸
29
+ * 补丁,无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
30
+ * @param ctx - 宿主上下文。
31
+ * @param config - 活动字段形态的行级 config(测试可传平面值)。
28
32
  */
29
- declare function apply(ctx: Context, config: WebCacheHeadersConfig): void;
33
+ declare function apply(ctx: Context, config: WebCacheHeadersConfig | WebCacheHeadersConfigFields): void;
30
34
  //#endregion
31
35
  export { Config, SETTINGS_NS, type WebCacheHeadersConfig, apply, name };
package/lib/index.js CHANGED
@@ -1,25 +1,6 @@
1
- import z from "@deepseek-ai/schemastery";
1
+ import { unwrapVolatile } from "@dsh-plus/shared";
2
2
  import http from "node:http";
3
- //#region src/config.ts
4
- /**
5
- * 插件配置(schemastery):可调参数一律外部化,不在逻辑里硬编码。
6
- *
7
- * 与仓库既有约定一致:Config 由 cordis 行级 config 解析,部署方可在
8
- * profile 的 cordis.patch.yml 覆盖;同时经 settings namespace 暴露到
9
- * $DSH_HOME/settings.yaml 用户层,修改热生效(无需 /reload)。
10
- * @module @dsh-plus/web-cache-headers/config
11
- */
12
- const Config = z.object({ enabled: z.boolean().description("总开关(false = 卸下补丁,响应头恢复 dsh 原生行为);development 环境恒禁用以保护 dev/HMR").default(true) });
13
- //#endregion
14
- //#region src/ns.ts
15
- /**
16
- * settings 命名空间字面量(纯常量,零依赖)。
17
- * 服务端以字面量注册 settings section(用户层配置落 $DSH_HOME/settings.yaml,
18
- * 热生效);与行级 cordis Config 共用同一份 schemastery schema(config.ts)。
19
- * @module @dsh-plus/web-cache-headers/ns
20
- */
21
- const SETTINGS_NS = "dsh-plus-web-cache-headers";
22
- //#endregion
3
+ import z from "@deepseek-ai/schemastery";
23
4
  //#region src/decision.ts
24
5
  /**
25
6
  * 缓存头决策(纯函数,零 IO):给定请求方法、URL、响应状态与「响应是否已带
@@ -102,14 +83,34 @@ function uninstallImmutableAssetsPatch() {
102
83
  originalWriteHead = void 0;
103
84
  }
104
85
  //#endregion
86
+ //#region src/config.ts
87
+ /**
88
+ * 插件配置(schemastery):可调参数一律外部化,不在逻辑里硬编码。
89
+ *
90
+ * 与仓库既有约定一致:Config 由 cordis 行级 config 解析,部署方可在
91
+ * profile 的 cordis.patch.yml 覆盖;同时经 settings namespace 暴露到
92
+ * $DSH_HOME/settings.yaml 用户层,修改热生效(无需 /reload)。
93
+ * @module @dsh-plus/web-cache-headers/config
94
+ */
95
+ const Config = z.object({ enabled: z.boolean().description("总开关(false = 卸下补丁,响应头恢复 dsh 原生行为);development 环境恒禁用以保护 dev/HMR").default(true).volatile() });
96
+ //#endregion
97
+ //#region src/ns.ts
98
+ /**
99
+ * settings 命名空间字面量(纯常量,零依赖)。
100
+ * 服务端以字面量注册 settings section(用户层配置落 $DSH_HOME/settings.yaml,
101
+ * 热生效);与行级 cordis Config 共用同一份 schemastery schema(config.ts)。
102
+ * @module @dsh-plus/web-cache-headers/ns
103
+ */
104
+ const SETTINGS_NS = "dsh-plus-web-cache-headers";
105
+ //#endregion
105
106
  //#region src/index.ts
106
107
  const name = "dsh-plus-web-cache-headers";
107
108
  /**
108
- * 装配补丁并接线配置源:settings 用户层($DSH_HOME/settings.yaml,热生效)
109
- * 优先,缺席/detach 回落 cordis 行级 config。enabled 翻转即时装/卸补丁,
110
- * 无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
111
- * @param ctx - 宿主上下文(settings 可选)。
112
- * @param config - 行级 config(settings 缺席时的默认值来源)。
109
+ * 装配补丁并接线配置源:0.1.7 起配置为 loader 解析的 volatile 活动字段
110
+ * (用户层 override 并入行级 config,写入原位提交),enabled 翻转即时装/卸
111
+ * 补丁,无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
112
+ * @param ctx - 宿主上下文。
113
+ * @param config - 活动字段形态的行级 config(测试可传平面值)。
113
114
  */
114
115
  function apply(ctx, config) {
115
116
  const logger = ctx.logger("web-cache-headers");
@@ -125,17 +126,8 @@ function apply(ctx, config) {
125
126
  installed = enabled;
126
127
  logger.info(enabled ? "已装配 /assets immutable 缓存头补丁" : "已卸下缓存头补丁(恢复 dsh 原生行为)");
127
128
  };
128
- let current = () => config;
129
- ctx.inject(["settings"], (settingsCtx) => {
130
- settingsCtx.settings.installSection(ctx, SETTINGS_NS, Config, config, {
131
- setSource: (source) => {
132
- current = source;
133
- },
134
- onChange: () => {
135
- sync(current().enabled);
136
- }
137
- });
138
- });
129
+ const current = () => unwrapVolatile(config);
130
+ ctx.events.on("loader/volatile-update", () => sync(current().enabled));
139
131
  sync(current().enabled);
140
132
  ctx.effect(() => () => sync(false), "web-cache-headers: dispose 卸下补丁");
141
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plus/web-cache-headers",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "dsh-plus service plugin: GUI 静态资源长缓存——为内容哈希的 /assets/* 响应补 `Cache-Control: immutable`(/plugins 官方已自带),消除每次刷新重复传输 ~1.4MB JS/CSS;进程级 writeHead 增量拦截,零路由注册、零 dsh 服务耦合,已有缓存头优先保证未来共存",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -17,15 +17,18 @@
17
17
  "lib",
18
18
  "src"
19
19
  ],
20
+ "dependencies": {
21
+ "@dsh-plus/shared": "0.1.22"
22
+ },
20
23
  "peerDependencies": {
21
- "@deepseek-ai/cordis": "^4.0.2",
22
- "@deepseek-ai/dsh-settings": "^0.1.6-alpha.2",
23
- "@deepseek-ai/schemastery": "^3.18.2"
24
+ "@deepseek-ai/cordis": "^4.0.4",
25
+ "@deepseek-ai/dsh-settings": "^0.1.7-alpha.2",
26
+ "@deepseek-ai/schemastery": "^3.18.4"
24
27
  },
25
28
  "devDependencies": {
26
- "@deepseek-ai/cordis": "4.0.2",
27
- "@deepseek-ai/dsh-settings": "0.1.6-alpha.2",
28
- "@deepseek-ai/schemastery": "3.18.2"
29
+ "@deepseek-ai/cordis": "4.0.4",
30
+ "@deepseek-ai/dsh-settings": "0.1.7-alpha.2",
31
+ "@deepseek-ai/schemastery": "3.18.4"
29
32
  },
30
33
  "publishConfig": {
31
34
  "access": "public"
package/src/config.ts CHANGED
@@ -7,14 +7,21 @@
7
7
  * @module @dsh-plus/web-cache-headers/config
8
8
  */
9
9
  import z from '@deepseek-ai/schemastery'
10
+ import type { UnwrapVolatile } from '@dsh-plus/shared'
10
11
 
12
+ // 0.1.7:`.volatile()` 使条目进入 settings describe 视图(卡片可读写)并让
13
+ // loader 以活动引用原位提交热更新。
11
14
  export const Config = z.object({
12
15
  enabled: z
13
16
  .boolean()
14
17
  .description(
15
18
  '总开关(false = 卸下补丁,响应头恢复 dsh 原生行为);development 环境恒禁用以保护 dev/HMR',
16
19
  )
17
- .default(true),
20
+ .default(true)
21
+ .volatile(),
18
22
  })
19
23
 
20
- export type WebCacheHeadersConfig = Schemastery.TypeT<typeof Config>
24
+ /** 活动字段形态(0.1.7 loader 解析产物:volatile 字段为活动引用)。 */
25
+ export type WebCacheHeadersConfigFields = Schemastery.TypeT<typeof Config>
26
+ /** 平面配置形态(消费面的读取形态,由活动引用解包得到)。 */
27
+ export type WebCacheHeadersConfig = UnwrapVolatile<WebCacheHeadersConfigFields>
package/src/index.ts CHANGED
@@ -23,26 +23,30 @@
23
23
  */
24
24
  import type { Context } from '@deepseek-ai/cordis'
25
25
  import type {} from '@deepseek-ai/dsh-settings'
26
+ import { unwrapVolatile } from '@dsh-plus/shared'
26
27
 
27
- import { Config, type WebCacheHeadersConfig } from './config.ts'
28
- import { SETTINGS_NS } from './ns.ts'
28
+ import type { WebCacheHeadersConfig, WebCacheHeadersConfigFields } from './config.ts'
29
29
  import { installImmutableAssetsPatch, uninstallImmutableAssetsPatch } from './patch.ts'
30
30
 
31
31
  export const name = 'dsh-plus-web-cache-headers'
32
32
 
33
33
  /** 无硬 inject:见模块头「结构守卫」。 */
34
34
 
35
+ export { Config } from './config.ts'
36
+ export { SETTINGS_NS } from './ns.ts'
35
37
  export type { WebCacheHeadersConfig }
36
- export { Config, SETTINGS_NS }
37
38
 
38
39
  /**
39
- * 装配补丁并接线配置源:settings 用户层($DSH_HOME/settings.yaml,热生效)
40
- * 优先,缺席/detach 回落 cordis 行级 config。enabled 翻转即时装/卸补丁,
41
- * 无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
42
- * @param ctx - 宿主上下文(settings 可选)。
43
- * @param config - 行级 config(settings 缺席时的默认值来源)。
40
+ * 装配补丁并接线配置源:0.1.7 起配置为 loader 解析的 volatile 活动字段
41
+ * (用户层 override 并入行级 config,写入原位提交),enabled 翻转即时装/卸
42
+ * 补丁,无需 /reload;插件 dispose(profile 卸载 / live reload)保证卸下。
43
+ * @param ctx - 宿主上下文。
44
+ * @param config - 活动字段形态的行级 config(测试可传平面值)。
44
45
  */
45
- export function apply(ctx: Context, config: WebCacheHeadersConfig): void {
46
+ export function apply(
47
+ ctx: Context,
48
+ config: WebCacheHeadersConfig | WebCacheHeadersConfigFields,
49
+ ): void {
46
50
  const logger = ctx.logger('web-cache-headers')
47
51
  if (process.env.NODE_ENV === 'development') {
48
52
  logger.info('development 环境:自动禁用(保护 dev/HMR 同 URL 热更新)')
@@ -60,17 +64,10 @@ export function apply(ctx: Context, config: WebCacheHeadersConfig): void {
60
64
  )
61
65
  }
62
66
 
63
- let current: () => WebCacheHeadersConfig = () => config
64
- ctx.inject(['settings'], (settingsCtx) => {
65
- settingsCtx.settings.installSection(ctx, SETTINGS_NS, Config, config, {
66
- setSource: (source) => {
67
- current = source
68
- },
69
- onChange: () => {
70
- sync(current().enabled)
71
- },
72
- })
73
- })
67
+ // 活动引用原位提交(替代 0.1.6 setSource/onChange):每次读现取平面快照,
68
+ // volatile 提交事件驱动 enabled 翻转装卸。
69
+ const current = (): WebCacheHeadersConfig => unwrapVolatile(config)
70
+ ctx.events.on('loader/volatile-update', () => sync(current().enabled))
74
71
 
75
72
  sync(current().enabled)
76
73
  ctx.effect(() => () => sync(false), 'web-cache-headers: dispose 卸下补丁')