swpp-backends 3.0.0-alpha.3 → 3.0.0-alpha.310

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.
Files changed (58) hide show
  1. package/{types → dist}/index.d.ts +5 -4
  2. package/dist/index.js +25 -17
  3. package/{types → dist}/swpp/FileParser.d.ts +11 -6
  4. package/dist/swpp/FileParser.js +27 -13
  5. package/{types → dist}/swpp/JsonBuilder.d.ts +1 -3
  6. package/dist/swpp/JsonBuilder.js +3 -7
  7. package/dist/swpp/NetworkFileHandler.js +3 -3
  8. package/{types → dist}/swpp/ResourcesScanner.d.ts +11 -14
  9. package/dist/swpp/ResourcesScanner.js +94 -70
  10. package/{types → dist}/swpp/SwCompiler.d.ts +21 -8
  11. package/dist/swpp/SwCompiler.js +49 -15
  12. package/{types → dist}/swpp/config/ConfigCluster.d.ts +98 -63
  13. package/dist/swpp/config/ConfigCluster.js +60 -48
  14. package/dist/swpp/config/ConfigLoader.d.ts +78 -0
  15. package/dist/swpp/config/ConfigLoader.js +180 -89
  16. package/dist/swpp/config/SpecialConfig.d.ts +29 -0
  17. package/dist/swpp/config/SpecialConfig.js +53 -0
  18. package/{types → dist}/swpp/database/CompilationEnv.d.ts +19 -16
  19. package/dist/swpp/database/CompilationEnv.js +41 -197
  20. package/dist/swpp/database/CompilationFileParser.d.ts +81 -0
  21. package/dist/swpp/database/CompilationFileParser.js +267 -0
  22. package/{types → dist}/swpp/database/CrossDepCode.d.ts +4 -0
  23. package/dist/swpp/database/CrossDepCode.js +27 -1
  24. package/dist/swpp/database/CrossEnv.js +19 -2
  25. package/{types → dist}/swpp/database/DomCode.d.ts +4 -1
  26. package/dist/swpp/database/DomCode.js +34 -5
  27. package/dist/swpp/database/KeyValueDatabase.d.ts +72 -0
  28. package/dist/swpp/database/KeyValueDatabase.js +122 -27
  29. package/{types → dist}/swpp/database/RuntimeCoreCode.d.ts +2 -1
  30. package/dist/swpp/database/RuntimeCoreCode.js +6 -5
  31. package/{types → dist}/swpp/database/RuntimeDepCode.d.ts +8 -14
  32. package/dist/swpp/database/RuntimeDepCode.js +30 -50
  33. package/{types → dist}/swpp/database/RuntimeEventCode.d.ts +4 -0
  34. package/dist/swpp/database/RuntimeEventCode.js +8 -1
  35. package/{types → dist}/swpp/database/RuntimeKeyValueDatabase.d.ts +1 -1
  36. package/dist/swpp/database/RuntimeKeyValueDatabase.js +2 -2
  37. package/dist/swpp/debug/CallChainRecorder.d.ts +5 -0
  38. package/dist/swpp/debug/CallChainRecorder.js +29 -0
  39. package/{types → dist}/swpp/untils.d.ts +25 -18
  40. package/dist/swpp/untils.js +47 -53
  41. package/package.json +2 -2
  42. package/types/DomBuilder.d.ts +0 -6
  43. package/types/FileAnalyzer.d.ts +0 -96
  44. package/types/ServiceWorkerBuilder.d.ts +0 -7
  45. package/types/SwppConfig.d.ts +0 -139
  46. package/types/SwppRules.d.ts +0 -117
  47. package/types/UpdateJsonBuilder.d.ts +0 -44
  48. package/types/Utils.d.ts +0 -43
  49. package/types/Variant.d.ts +0 -58
  50. package/types/VersionAnalyzer.d.ts +0 -27
  51. package/types/browser/ServiceWorkerRuntimeTypes.d.ts +0 -18
  52. package/types/swpp/RuntimeEnv.d.ts +0 -39
  53. package/types/swpp/SwCodeInject.d.ts +0 -17
  54. package/types/swpp/config/ConfigLoader.d.ts +0 -53
  55. package/types/swpp/database/KeyValueDatabase.d.ts +0 -53
  56. package/types/swpp/database/RuntimeEnv.d.ts +0 -5
  57. /package/{types → dist}/swpp/NetworkFileHandler.d.ts +0 -0
  58. /package/{types → dist}/swpp/database/CrossEnv.d.ts +0 -0
@@ -3,126 +3,144 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ConfigLoader = exports.IndivisibleName = void 0;
6
+ exports.ConfigLoader = void 0;
7
+ exports.defineConfig = defineConfig;
8
+ exports.defineCompilationEnv = defineCompilationEnv;
9
+ exports.defineCompilationFP = defineCompilationFP;
10
+ exports.defineCrossEnv = defineCrossEnv;
11
+ exports.defineRuntimeDep = defineRuntimeDep;
12
+ exports.defineCrossDep = defineCrossDep;
13
+ exports.defineRuntimeCore = defineRuntimeCore;
14
+ exports.defineDomConfig = defineDomConfig;
15
+ exports.defineRuntimeEvent = defineRuntimeEvent;
16
+ exports.defineModifier = defineModifier;
7
17
  const jiti_1 = require("jiti");
8
18
  const path_1 = __importDefault(require("path"));
9
- const CompilationEnv_1 = require("../database/CompilationEnv");
10
19
  const SwCompiler_1 = require("../SwCompiler");
11
20
  const untils_1 = require("../untils");
12
- exports.IndivisibleName = '1indivisible__';
21
+ const SpecialConfig_1 = require("./SpecialConfig");
22
+ /** 正在加载配置的 loader */
23
+ let activeConfigLoader = null;
24
+ const TMP_PW = Math.random().toString();
13
25
  class ConfigLoader {
14
26
  constructor() {
15
27
  this.modifierList = [];
16
- this.isBuilt = false;
28
+ Object.defineProperty(this, '9zLoadFromInside', {
29
+ value: (config, pw) => {
30
+ if (pw !== TMP_PW)
31
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.error, '该函数仅能由内部调用');
32
+ if ('modifier' in config) {
33
+ this.modifierList.push(config.modifier);
34
+ }
35
+ if (this.config)
36
+ ConfigLoader.mergeConfig(this.config, config);
37
+ else
38
+ this.config = config;
39
+ },
40
+ writable: false,
41
+ enumerable: false
42
+ });
17
43
  }
18
44
  // noinspection JSUnusedGlobalSymbols
19
45
  /**
20
46
  * 加载一个配置文件,越早加载的优先级越高
21
- * @param file
47
+ * @param file 配置文件的绝对路径
22
48
  */
23
49
  async load(file) {
24
- if (this.isBuilt)
25
- throw {
26
- code: untils_1.exceptionNames.configBuilt,
27
- message: '配置文件已经完成构建,不能继续加载新的配置',
28
- file
29
- };
30
- const extensionName = path_1.default.extname(file);
50
+ const extensionName = path_1.default.extname(file).substring(1);
31
51
  if (!ConfigLoader.extensions.includes(extensionName)) {
32
- throw {
33
- code: untils_1.exceptionNames.unsupportedFileType,
34
- message: `配置文件传入了不支持的文件类型:${extensionName},仅支持:${ConfigLoader.extensions}`,
35
- file
36
- };
52
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.unsupportedFileType, `配置文件传入了不支持的文件类型:${extensionName},仅支持:${ConfigLoader.extensions}`, { configPath: file });
37
53
  }
54
+ await ConfigLoader.waitLoad();
55
+ let error = true;
56
+ activeConfigLoader?.onRelease?.();
57
+ activeConfigLoader = new ConfigLoaderLock(this, () => {
58
+ if (error)
59
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.error, '锁竞争时出现异常');
60
+ }, path_1.default.normalize(file));
61
+ const task = ConfigLoader.prevTask = ConfigLoader.jiti.import(file).then(() => error = false);
62
+ await task;
63
+ }
64
+ /**
65
+ * 加载一个在代码层面编写的配置
66
+ */
67
+ // noinspection JSUnusedGlobalSymbols
68
+ async loadFromCode(config) {
69
+ await ConfigLoader.waitLoad();
38
70
  // @ts-ignore
39
- const content = await ConfigLoader.jiti.import(file);
40
- let newConfig = 'default' in content ? content.default : content;
41
- if ('modifier' in newConfig) {
42
- this.modifierList.push(newConfig.modifier);
43
- }
44
- if (this.config)
45
- this.mergeConfig(newConfig);
46
- else
47
- this.config = newConfig;
71
+ this['9zLoadFromInside'](config, TMP_PW);
72
+ }
73
+ static async waitLoad() {
74
+ let prev;
75
+ do {
76
+ prev = ConfigLoader.prevTask;
77
+ await prev;
78
+ } while (prev !== ConfigLoader.prevTask);
48
79
  }
49
80
  // noinspection JSUnusedGlobalSymbols
50
81
  /** 将配置项的内容写入到环境中 */
51
82
  generate() {
52
83
  if (!this.config)
53
- throw {
54
- code: untils_1.exceptionNames.nullPoint,
55
- message: '构建配之前必须至少加载一个配置文件'
56
- };
84
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.nullPoint, '构建配之前必须至少加载一个配置文件');
57
85
  // 构建属性集
58
86
  const { runtime, compilation } = (this.modifierList.find(it => it.build)?.build ?? (() => {
59
- const runtime = new SwCompiler_1.RuntimeData();
60
- const compilation = {
61
- compilationEnv: new CompilationEnv_1.CompilationEnv(runtime.crossEnv, runtime.crossDep),
62
- crossDep: runtime.crossDep,
63
- crossEnv: runtime.crossEnv
64
- };
87
+ const compilation = new SwCompiler_1.CompilationData();
88
+ const runtime = new SwCompiler_1.RuntimeData(compilation);
65
89
  return { runtime, compilation };
66
90
  }))();
91
+ runtime.initCompilation(compilation);
92
+ compilation.initRuntime(runtime);
67
93
  const config = this.config;
94
+ /** 将指定配置项目写入到 KV 库中 */
95
+ const writeConfigToKv = (key, value, database) => {
96
+ if (SpecialConfig_1.SpecialConfig.isNoCacheConfig(value)) {
97
+ database.update(key, value);
98
+ }
99
+ else {
100
+ if (typeof value === 'object') {
101
+ const def = database.readDefault(key);
102
+ ConfigLoader.mergeConfig(value, def, false);
103
+ }
104
+ database.update(key, value ?? null);
105
+ }
106
+ };
68
107
  // 写入运行时信息
69
108
  const writeRuntime = () => {
70
- const insertList = ['runtimeDep', 'runtimeCore', 'runtimeEvent'];
71
- for (let str of insertList) {
72
- const configValue = config[str];
73
- if (!configValue)
109
+ for (let configKey in config) {
110
+ if (!/^(runtime|dom)[A-Z_]/.test(configKey))
74
111
  continue;
112
+ const configValue = config[configKey];
113
+ const database = runtime.getDatabase(configKey);
75
114
  for (let key in configValue) {
76
- const value = configValue[key];
77
- runtime.runtimeDep.update(key, () => value ?? null);
115
+ writeConfigToKv(key, configValue[key], database);
78
116
  }
79
117
  }
80
118
  };
81
119
  // 写入编译期信息
82
120
  const writeCompilation = () => {
83
121
  if (!config.compilationEnv)
84
- throw {
85
- code: untils_1.exceptionNames.nullPoint,
86
- message: '配置项必须包含 compilationEnv 选项!'
87
- };
88
- for (let key in config.compilationEnv) {
89
- const value = config.compilationEnv[key];
90
- compilation.compilationEnv.update(key, () => value);
122
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.nullPoint, '配置项必须包含 compilationEnv 选项!');
123
+ for (let configKey in config) {
124
+ if (!/^compilation[A-Z_]/.test(configKey))
125
+ continue;
126
+ if (!(configKey in compilation)) {
127
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.nullPoint, `配置项中传入了一个不存在的分类[${configKey}]`);
128
+ }
129
+ const env = config[configKey];
130
+ for (let key in env) {
131
+ writeConfigToKv(key, env[key], compilation[configKey]);
132
+ }
91
133
  }
92
134
  };
93
135
  // 写入 cross
94
136
  const writeCross = () => {
95
- if (config.crossEnv) {
96
- for (let key in config.crossEnv) {
97
- const env = config.crossEnv[key];
98
- const value = typeof env === 'function' ? env.call(compilation) : env;
99
- if (typeof value === 'function')
100
- throw {
101
- code: untils_1.exceptionNames.invalidVarType,
102
- message: `crossEnv[${key}] 应当返回一个非函数对象,却返回了:${value.toString()}`
103
- };
104
- runtime.crossEnv.update(key, () => value);
105
- }
106
- }
107
- if (config.crossDep) {
108
- for (let key in config.crossDep) {
109
- const value = config.crossDep[key];
110
- if (typeof value != 'object')
111
- throw {
112
- code: untils_1.exceptionNames.invalidVarType,
113
- message: `crossDep[${key}] 返回的内容应当为一个对象,却返回了:${value}`
114
- };
115
- if (!('runOnNode' in value))
116
- throw {
117
- code: untils_1.exceptionNames.invalidVarType,
118
- message: `crossDep[${key}] 返回的对象应当包含 {runOnNode} 字段,却返回了:${JSON.stringify(value, null, 2)}`
119
- };
120
- if (!('runOnBrowser' in value))
121
- throw {
122
- code: untils_1.exceptionNames.invalidVarType,
123
- message: `crossDep[${key}] 返回的对象应当包含 {runOnBrowser} 字段,却返回了:${JSON.stringify(value, null, 2)}`
124
- };
125
- runtime.crossDep.update(key, () => value);
137
+ for (let configKey in config) {
138
+ if (!/^cross[A-Z_]/.test(configKey))
139
+ continue;
140
+ const env = config[configKey];
141
+ const database = runtime.getDatabase(configKey);
142
+ for (let key in env) {
143
+ writeConfigToKv(key, env[key], database);
126
144
  }
127
145
  }
128
146
  };
@@ -134,15 +152,21 @@ class ConfigLoader {
134
152
  writeRuntime();
135
153
  writeCompilation();
136
154
  writeCross();
137
- // 运行 dynamic
155
+ // 运行 dynamicUpdate
138
156
  for (let i = this.modifierList.length - 1; i >= 0; i--) {
139
157
  const modifier = this.modifierList[i];
140
- modifier.dynamic?.(runtime, compilation);
158
+ modifier.dynamicUpdate?.(runtime, compilation);
141
159
  }
160
+ // 冻结 KV 库
161
+ runtime.freezeAll();
162
+ compilation.freezeAll();
163
+ Object.freeze(runtime.insertOrder);
164
+ Object.freeze(runtime);
165
+ Object.freeze(compilation);
142
166
  return Object.freeze({ runtime, compilation });
143
167
  }
144
168
  /** 将新配置合并到已有配置中 */
145
- mergeConfig(other) {
169
+ static mergeConfig(config, other, isTop = true) {
146
170
  function mergeHelper(high, low, skip) {
147
171
  for (let key in low) {
148
172
  if (skip && key == 'modifier')
@@ -156,7 +180,7 @@ class ConfigLoader {
156
180
  }
157
181
  if (typeof highValue != typeof lowValue)
158
182
  continue;
159
- if (typeof highValue == 'object' && !highValue[exports.IndivisibleName] && !lowValue[exports.IndivisibleName]) {
183
+ if (typeof highValue == 'object' && !SpecialConfig_1.SpecialConfig.isIndivisibleConfig(highValue)) {
160
184
  mergeHelper(highValue, lowValue, false);
161
185
  }
162
186
  }
@@ -165,7 +189,7 @@ class ConfigLoader {
165
189
  }
166
190
  }
167
191
  }
168
- mergeHelper(this.config, other, true);
192
+ mergeHelper(config, other, isTop);
169
193
  }
170
194
  }
171
195
  exports.ConfigLoader = ConfigLoader;
@@ -174,8 +198,75 @@ ConfigLoader.extensions = [
174
198
  'js', 'ts', 'cjs', 'cts', 'mjs', 'mjs'
175
199
  ];
176
200
  ConfigLoader.jiti = (0, jiti_1.createJiti)(__filename, {
177
- fsCache: false,
178
- alias: {
179
- 'swpp-backends': path_1.default.join(__dirname, '..', '..', 'index')
180
- }
201
+ fsCache: false
181
202
  });
203
+ ConfigLoader.prevTask = null;
204
+ class ConfigLoaderLock {
205
+ constructor(loader, onRelease, file) {
206
+ this.loader = loader;
207
+ this.onRelease = onRelease;
208
+ this.file = file;
209
+ }
210
+ check(file) {
211
+ if (file !== this.file)
212
+ throw new untils_1.RuntimeException(untils_1.exceptionNames.error, `错误地在 ${this.file} 加载时期载入了 ${file} 中的配置`);
213
+ }
214
+ }
215
+ function invokeLoader(loader, config) {
216
+ const stack = new Error().stack.split('\n');
217
+ const dist = stack[3];
218
+ let filePath;
219
+ if (dist.endsWith(')')) {
220
+ const startIndex = dist.lastIndexOf('(');
221
+ const endIndex = untils_1.utils.findSecondLastIndex(dist, ':');
222
+ filePath = dist.substring(startIndex + 1, endIndex);
223
+ }
224
+ else {
225
+ const startIndex = dist.indexOf('at ');
226
+ const endIndex = untils_1.utils.findSecondLastIndex(dist, ':');
227
+ filePath = dist.substring(startIndex + 3, endIndex);
228
+ }
229
+ activeConfigLoader.check(path_1.default.normalize(filePath));
230
+ // @ts-ignore
231
+ loader['9zLoadFromInside'](config, TMP_PW);
232
+ }
233
+ /** 定义一个通过 `export default` 导出的配置 */
234
+ function defineConfig(config) {
235
+ invokeLoader(activeConfigLoader.loader, config);
236
+ }
237
+ /** 定义一个通过 `export const compilationEnv` 导出的配置 */
238
+ function defineCompilationEnv(config) {
239
+ invokeLoader(activeConfigLoader.loader, { compilationEnv: config });
240
+ }
241
+ /** 定义一个通过 `export const compilationFileParser` 导出的配置 */
242
+ function defineCompilationFP(config) {
243
+ invokeLoader(activeConfigLoader.loader, { compilationFileParser: config });
244
+ }
245
+ /** 定义一个通过 `export const crossEnv` 导出的配置 */
246
+ function defineCrossEnv(config) {
247
+ invokeLoader(activeConfigLoader.loader, { crossEnv: config });
248
+ }
249
+ /** 定义一个通过 `export const runtimeDep` 导出的配置 */
250
+ function defineRuntimeDep(config) {
251
+ invokeLoader(activeConfigLoader.loader, { runtimeDep: config });
252
+ }
253
+ /** 定义一个通过 `export const crossDep` 导出的配置 */
254
+ function defineCrossDep(config) {
255
+ invokeLoader(activeConfigLoader.loader, { crossDep: config });
256
+ }
257
+ /** 定义一个通过 `export const runtimeCore` 导出的配置 */
258
+ function defineRuntimeCore(config) {
259
+ invokeLoader(activeConfigLoader.loader, { runtimeCore: config });
260
+ }
261
+ /** 定义一个通过 `export const domConfig` 导出的配置 */
262
+ function defineDomConfig(config) {
263
+ invokeLoader(activeConfigLoader.loader, { domConfig: config });
264
+ }
265
+ /** 定义一个通过 `export const runtimeEvent` 导出的配置 */
266
+ function defineRuntimeEvent(config) {
267
+ invokeLoader(activeConfigLoader.loader, { runtimeEvent: config });
268
+ }
269
+ /** 定义一个通过 `export const modifier` 导出的配置 */
270
+ function defineModifier(config) {
271
+ invokeLoader(activeConfigLoader.loader, { modifier: config });
272
+ }
@@ -0,0 +1,29 @@
1
+ import { CompilationData, RuntimeData } from '../SwCompiler';
2
+ export type RuntimeSupplier<T> = (runtime: RuntimeData, compilation: CompilationData) => T;
3
+ export declare class SpecialConfig {
4
+ static isSpecialConfig(config: any): config is RuntimeSpecialConfig<any>;
5
+ static isIndivisibleConfig(config: any): config is IndivisibleConfig<any> | RuntimeSpecialConfig<any>;
6
+ static isNoCacheConfig(config: any): config is NoCacheConfig<any>;
7
+ }
8
+ /** 运行时特殊配置 */
9
+ export declare abstract class RuntimeSpecialConfig<T> extends SpecialConfig {
10
+ abstract get(runtime: RuntimeData, compilation: CompilationData): T;
11
+ }
12
+ /** 不可分割的配置 */
13
+ export declare class IndivisibleConfig<T> extends SpecialConfig {
14
+ readonly value: T;
15
+ constructor(value: T);
16
+ }
17
+ /** 不被缓存的配置 */
18
+ export declare class NoCacheConfig<T> extends RuntimeSpecialConfig<T> {
19
+ private getter;
20
+ constructor(getter: RuntimeSupplier<T>);
21
+ get(runtime: RuntimeData, compilation: CompilationData): T;
22
+ }
23
+ /** 延迟初始化配置 */
24
+ export declare class LazyInitConfig<T> extends RuntimeSpecialConfig<T> {
25
+ private getter;
26
+ private cache;
27
+ constructor(getter: RuntimeSupplier<T>);
28
+ get(runtime: RuntimeData, compilation: CompilationData): T;
29
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LazyInitConfig = exports.NoCacheConfig = exports.IndivisibleConfig = exports.RuntimeSpecialConfig = exports.SpecialConfig = void 0;
4
+ class SpecialConfig {
5
+ static isSpecialConfig(config) {
6
+ return config instanceof RuntimeSpecialConfig;
7
+ }
8
+ static isIndivisibleConfig(config) {
9
+ return config instanceof IndivisibleConfig || config instanceof RuntimeSpecialConfig;
10
+ }
11
+ static isNoCacheConfig(config) {
12
+ return config instanceof NoCacheConfig;
13
+ }
14
+ }
15
+ exports.SpecialConfig = SpecialConfig;
16
+ /** 运行时特殊配置 */
17
+ class RuntimeSpecialConfig extends SpecialConfig {
18
+ }
19
+ exports.RuntimeSpecialConfig = RuntimeSpecialConfig;
20
+ /** 不可分割的配置 */
21
+ class IndivisibleConfig extends SpecialConfig {
22
+ constructor(value) {
23
+ super();
24
+ this.value = value;
25
+ }
26
+ }
27
+ exports.IndivisibleConfig = IndivisibleConfig;
28
+ /** 不被缓存的配置 */
29
+ class NoCacheConfig extends RuntimeSpecialConfig {
30
+ constructor(getter) {
31
+ super();
32
+ this.getter = getter;
33
+ }
34
+ get(runtime, compilation) {
35
+ return this.getter(runtime, compilation);
36
+ }
37
+ }
38
+ exports.NoCacheConfig = NoCacheConfig;
39
+ /** 延迟初始化配置 */
40
+ class LazyInitConfig extends RuntimeSpecialConfig {
41
+ constructor(getter) {
42
+ super();
43
+ this.getter = getter;
44
+ }
45
+ get(runtime, compilation) {
46
+ if (this.getter) {
47
+ this.cache = this.getter(runtime, compilation);
48
+ this.getter = null;
49
+ }
50
+ return this.cache;
51
+ }
52
+ }
53
+ exports.LazyInitConfig = LazyInitConfig;
@@ -1,15 +1,14 @@
1
- import { FileParserRegistry } from '../FileParser';
2
1
  import { UpdateJson } from '../JsonBuilder';
3
2
  import { FiniteConcurrencyFetcher } from '../NetworkFileHandler';
4
- import { CrossDepCode } from './CrossDepCode';
5
- import { CrossEnv } from './CrossEnv';
3
+ import { FileUpdateTracker } from '../ResourcesScanner';
4
+ import { CompilationData } from '../SwCompiler';
6
5
  import { KeyValueDatabase } from './KeyValueDatabase';
7
6
  export type COMMON_TYPE_COMP_ENV = ReturnType<typeof buildCommon>;
8
7
  /**
9
8
  * 仅在编译期生效的配置项
10
9
  */
11
10
  export declare class CompilationEnv extends KeyValueDatabase<any, COMMON_TYPE_COMP_ENV> {
12
- constructor(crossEnv: CrossEnv, crossCode: CrossDepCode);
11
+ constructor();
13
12
  }
14
13
  /** 拉取版本信息和 tracker 时的 404 等级 */
15
14
  export declare enum AllowNotFoundEnum {
@@ -20,29 +19,33 @@ export declare enum AllowNotFoundEnum {
20
19
  /** 拒绝任意形式的 404 */
21
20
  REJECT_ALL = 2
22
21
  }
23
- declare function buildCommon(_env: any, crossEnv: CrossEnv, crossCode: CrossDepCode): {
24
- readonly DOMAIN_HOST: import("./KeyValueDatabase").DatabaseValue<string>;
25
- /** HTML 数量限制 */
22
+ declare function buildCommon(_env: any): {
23
+ readonly DOMAIN_HOST: import("./KeyValueDatabase").DatabaseValue<URL>;
24
+ readonly SERVICE_WORKER: import("./KeyValueDatabase").DatabaseValue<string>;
25
+ /** HTML 数量限制,设置为 <= 0 表示不限制 */
26
26
  readonly JSON_HTML_LIMIT: import("./KeyValueDatabase").DatabaseValue<number>;
27
27
  /** 版本信息长度限制 */
28
28
  readonly VERSION_LENGTH_LIMIT: import("./KeyValueDatabase").DatabaseValue<number>;
29
- /** 获取已经上线的版本文件 */
30
- readonly VERSION_FILE: import("./KeyValueDatabase").DatabaseValue<{
31
- path: string;
32
- fetcher(): Promise<UpdateJson>;
29
+ /** swpp 的 JSON 文件的基本信息 */
30
+ readonly SWPP_JSON_FILE: import("./KeyValueDatabase").DatabaseValue<{
31
+ swppPath: string;
32
+ trackerPath: string;
33
+ versionPath: string;
34
+ fetchVersionFile(): Promise<UpdateJson>;
35
+ fetchTrackerFile(compilation: CompilationData): Promise<FileUpdateTracker>;
33
36
  }>;
34
37
  /** 读取一个本地文件 */
35
- readonly LOCAL_FILE_READER: import("./KeyValueDatabase").DatabaseValue<(path: string) => Promise<string>>;
38
+ readonly readLocalFile: import("./KeyValueDatabase").DatabaseValue<(path: string) => Promise<string>>;
36
39
  /** 拉取网络文件 */
37
- readonly FETCH_NETWORK_FILE: import("./KeyValueDatabase").DatabaseValue<FiniteConcurrencyFetcher>;
40
+ readonly NETWORK_FILE_FETCHER: import("./KeyValueDatabase").DatabaseValue<FiniteConcurrencyFetcher>;
38
41
  /** 判断文件是否是 404 */
39
- readonly IS_NOT_FOUND: import("./KeyValueDatabase").DatabaseValue<{
42
+ readonly isNotFound: import("./KeyValueDatabase").DatabaseValue<{
40
43
  response: (response: Response) => boolean;
41
44
  error: (err: any) => boolean;
42
45
  }>;
43
46
  /** 是否允许 404 */
44
47
  readonly ALLOW_NOT_FOUND: import("./KeyValueDatabase").DatabaseValue<AllowNotFoundEnum>;
45
- /** 文件解析器 */
46
- readonly FILE_PARSER: import("./KeyValueDatabase").DatabaseValue<FileParserRegistry>;
48
+ /** 检查一个链接是否是稳定的(也就是 URL 不变其返回的结果永远不变) */
49
+ readonly isStable: import("./KeyValueDatabase").DatabaseValue<(_url: URL) => boolean>;
47
50
  };
48
51
  export {};