swpp-backends 3.0.0-alpha.0 → 3.0.0-alpha.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/dist/index.js CHANGED
@@ -1,7 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.version = void 0;
3
+ exports.AllowNotFoundEnum = exports.CompilationEnv = exports.CrossDepCode = exports.CrossEnv = exports.RuntimeDepCode = exports.RuntimeCoreCode = exports.RuntimeEventCode = exports.RuntimeKeyValueDatabase = exports.KeyValueDatabase = exports.defineIndivisibleConfig = exports.defineRuntimeEvent = exports.defineRuntimeCore = exports.defineRuntimeDep = exports.defineCrossDep = exports.defineCrossEnv = exports.defineConfig = exports.defineCompilationEnv = exports.ConfigLoader = exports.FiniteConcurrencyFetcher = exports.RuntimeData = exports.SwCompiler = exports.FileParserRegistry = exports.JsonBuilder = exports.FileUpdateTracker = exports.ResourcesScanner = exports.utils = exports.version = void 0;
4
4
  const untils_1 = require("./swpp/untils");
5
5
  /** 版本号 */
6
6
  exports.version = require('../package.json').version;
7
+ var untils_2 = require("./swpp/untils");
8
+ Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return untils_2.utils; } });
9
+ var ResourcesScanner_1 = require("./swpp/ResourcesScanner");
10
+ Object.defineProperty(exports, "ResourcesScanner", { enumerable: true, get: function () { return ResourcesScanner_1.ResourcesScanner; } });
11
+ Object.defineProperty(exports, "FileUpdateTracker", { enumerable: true, get: function () { return ResourcesScanner_1.FileUpdateTracker; } });
12
+ var JsonBuilder_1 = require("./swpp/JsonBuilder");
13
+ Object.defineProperty(exports, "JsonBuilder", { enumerable: true, get: function () { return JsonBuilder_1.JsonBuilder; } });
14
+ var FileParser_1 = require("./swpp/FileParser");
15
+ Object.defineProperty(exports, "FileParserRegistry", { enumerable: true, get: function () { return FileParser_1.FileParserRegistry; } });
16
+ var SwCompiler_1 = require("./swpp/SwCompiler");
17
+ Object.defineProperty(exports, "SwCompiler", { enumerable: true, get: function () { return SwCompiler_1.SwCompiler; } });
18
+ Object.defineProperty(exports, "RuntimeData", { enumerable: true, get: function () { return SwCompiler_1.RuntimeData; } });
19
+ var NetworkFileHandler_1 = require("./swpp/NetworkFileHandler");
20
+ Object.defineProperty(exports, "FiniteConcurrencyFetcher", { enumerable: true, get: function () { return NetworkFileHandler_1.FiniteConcurrencyFetcher; } });
21
+ var ConfigLoader_1 = require("./swpp/config/ConfigLoader");
22
+ Object.defineProperty(exports, "ConfigLoader", { enumerable: true, get: function () { return ConfigLoader_1.ConfigLoader; } });
23
+ Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCompilationEnv; } });
24
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineConfig; } });
25
+ Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossEnv; } });
26
+ Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossDep; } });
27
+ Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeDep; } });
28
+ Object.defineProperty(exports, "defineRuntimeCore", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeCore; } });
29
+ Object.defineProperty(exports, "defineRuntimeEvent", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeEvent; } });
30
+ Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineIndivisibleConfig; } });
31
+ var KeyValueDatabase_1 = require("./swpp/database/KeyValueDatabase");
32
+ Object.defineProperty(exports, "KeyValueDatabase", { enumerable: true, get: function () { return KeyValueDatabase_1.KeyValueDatabase; } });
33
+ var RuntimeKeyValueDatabase_1 = require("./swpp/database/RuntimeKeyValueDatabase");
34
+ Object.defineProperty(exports, "RuntimeKeyValueDatabase", { enumerable: true, get: function () { return RuntimeKeyValueDatabase_1.RuntimeKeyValueDatabase; } });
35
+ var RuntimeEventCode_1 = require("./swpp/database/RuntimeEventCode");
36
+ Object.defineProperty(exports, "RuntimeEventCode", { enumerable: true, get: function () { return RuntimeEventCode_1.RuntimeEventCode; } });
37
+ var RuntimeCoreCode_1 = require("./swpp/database/RuntimeCoreCode");
38
+ Object.defineProperty(exports, "RuntimeCoreCode", { enumerable: true, get: function () { return RuntimeCoreCode_1.RuntimeCoreCode; } });
39
+ var RuntimeDepCode_1 = require("./swpp/database/RuntimeDepCode");
40
+ Object.defineProperty(exports, "RuntimeDepCode", { enumerable: true, get: function () { return RuntimeDepCode_1.RuntimeDepCode; } });
41
+ var CrossEnv_1 = require("./swpp/database/CrossEnv");
42
+ Object.defineProperty(exports, "CrossEnv", { enumerable: true, get: function () { return CrossEnv_1.CrossEnv; } });
43
+ var CrossDepCode_1 = require("./swpp/database/CrossDepCode");
44
+ Object.defineProperty(exports, "CrossDepCode", { enumerable: true, get: function () { return CrossDepCode_1.CrossDepCode; } });
45
+ var CompilationEnv_1 = require("./swpp/database/CompilationEnv");
46
+ Object.defineProperty(exports, "CompilationEnv", { enumerable: true, get: function () { return CompilationEnv_1.CompilationEnv; } });
47
+ Object.defineProperty(exports, "AllowNotFoundEnum", { enumerable: true, get: function () { return CompilationEnv_1.AllowNotFoundEnum; } });
7
48
  untils_1.utils.printInfo('INDEX', `欢迎使用 swpp@${exports.version}`);
@@ -3,7 +3,8 @@ 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.buildFileParser = exports.FileParserRegistry = void 0;
6
+ exports.FileParserRegistry = void 0;
7
+ exports.buildFileParser = buildFileParser;
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const untils_1 = require("./untils");
9
10
  class FileParserRegistry {
@@ -82,4 +83,3 @@ exports.FileParserRegistry = FileParserRegistry;
82
83
  function buildFileParser(parser) {
83
84
  return parser;
84
85
  }
85
- exports.buildFileParser = buildFileParser;
@@ -15,6 +15,7 @@ class JsonBuilder {
15
15
  putHeader(key, value) {
16
16
  this.headers.set(key, value);
17
17
  }
18
+ // noinspection JSUnusedGlobalSymbols
18
19
  async buildJson() {
19
20
  const json = await this.compilation.compilationEnv.read('VERSION_FILE')();
20
21
  if (json.info.length == 0) {
@@ -30,6 +30,7 @@ exports.FileUpdateTracker = exports.ResourcesScanner = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const crypto = __importStar(require("node:crypto"));
32
32
  const path_1 = __importDefault(require("path"));
33
+ const CompilationEnv_1 = require("./database/CompilationEnv");
33
34
  const JsonBuilder_1 = require("./JsonBuilder");
34
35
  const untils_1 = require("./untils");
35
36
  /**
@@ -39,6 +40,7 @@ class ResourcesScanner {
39
40
  constructor(compilation) {
40
41
  this.compilation = compilation;
41
42
  }
43
+ // noinspection JSUnusedGlobalSymbols
42
44
  /** 扫描指定目录下的所有文件 */
43
45
  async scanLocalFile(path) {
44
46
  const matchCacheRule = this.compilation.crossDep.read('matchCacheRule');
@@ -159,6 +161,7 @@ class FileUpdateTracker {
159
161
  addUrl(url) {
160
162
  this.allUrl.add(url);
161
163
  }
164
+ // noinspection JSUnusedGlobalSymbols
162
165
  /**
163
166
  * 判断两个 tracker 的差异
164
167
  *
@@ -186,6 +189,7 @@ class FileUpdateTracker {
186
189
  });
187
190
  return diff;
188
191
  }
192
+ // noinspection JSUnusedGlobalSymbols
189
193
  /**
190
194
  * 将数据序列化为 JSON
191
195
  *
@@ -242,5 +246,45 @@ class FileUpdateTracker {
242
246
  }
243
247
  return tracker;
244
248
  }
249
+ // noinspection JSUnusedGlobalSymbols
250
+ /** 从网络拉取并解析 tracker */
251
+ static async parserJsonFromNetwork(compilation, url) {
252
+ const fetcher = compilation.compilationEnv.read('FETCH_NETWORK_FILE');
253
+ const isNotFound = compilation.compilationEnv.read('IS_NOT_FOUND');
254
+ const notFoundLevel = compilation.compilationEnv.read('ALLOW_NOT_FOUND');
255
+ let error;
256
+ const result = await (async () => {
257
+ try {
258
+ const response = await fetcher.fetch(url);
259
+ if (isNotFound.response(response)) {
260
+ if (notFoundLevel == CompilationEnv_1.AllowNotFoundEnum.REJECT_ALL) {
261
+ error = {
262
+ code: untils_1.exceptionNames.notFound,
263
+ message: `拉取 ${url} 时出现 404 错误`
264
+ };
265
+ return;
266
+ }
267
+ untils_1.utils.printWarning('SCANNER', '拉取 tracker 时服务器返回了 404,如果是第一次携带 swpp v3 构建网站请忽视这条信息');
268
+ return new FileUpdateTracker(compilation);
269
+ }
270
+ const text = await response.text();
271
+ return FileUpdateTracker.unJson(compilation, text);
272
+ }
273
+ catch (e) {
274
+ if (isNotFound.error(e) && notFoundLevel == CompilationEnv_1.AllowNotFoundEnum.ALLOW_ALL) {
275
+ untils_1.utils.printWarning('SCANNER', '拉取 tracker 时 DNS 解析失败,如果是第一次携带 swpp v3 构建网站且网站暂时无法解析请忽视这条信息');
276
+ return new FileUpdateTracker(compilation);
277
+ }
278
+ untils_1.utils.printError('SCANNER', e);
279
+ throw {
280
+ code: untils_1.exceptionNames.error,
281
+ message: `拉取或解析历史 Tracker 时出现错误`
282
+ };
283
+ }
284
+ })();
285
+ if (result)
286
+ return result;
287
+ throw error;
288
+ }
245
289
  }
246
290
  exports.FileUpdateTracker = FileUpdateTracker;
@@ -11,6 +11,7 @@ class SwCompiler {
11
11
  constructor() {
12
12
  this.swCode = '';
13
13
  }
14
+ // noinspection JSUnusedGlobalSymbols
14
15
  /**
15
16
  * 构建 sw 代码,该函数结果会被缓存
16
17
  */
@@ -3,14 +3,24 @@ 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.defineRuntimeEvent = exports.defineRuntimeCore = exports.defineCrossDep = exports.defineRuntimeDep = exports.defineCrossEnv = exports.defineCompilationEnv = exports.defineConfig = exports.ConfigLoader = void 0;
6
+ exports.ConfigLoader = void 0;
7
+ exports.defineConfig = defineConfig;
8
+ exports.defineCompilationEnv = defineCompilationEnv;
9
+ exports.defineCrossEnv = defineCrossEnv;
10
+ exports.defineRuntimeDep = defineRuntimeDep;
11
+ exports.defineCrossDep = defineCrossDep;
12
+ exports.defineRuntimeCore = defineRuntimeCore;
13
+ exports.defineRuntimeEvent = defineRuntimeEvent;
14
+ exports.defineIndivisibleConfig = defineIndivisibleConfig;
7
15
  const jiti_1 = require("jiti");
8
16
  const path_1 = __importDefault(require("path"));
9
17
  const untils_1 = require("../untils");
18
+ const IndivisibleName = '1indivisible__';
10
19
  class ConfigLoader {
11
20
  constructor() {
12
21
  this.isBuilt = false;
13
22
  }
23
+ // noinspection JSUnusedGlobalSymbols
14
24
  /**
15
25
  * 加载一个配置文件,越早加载的优先级越高
16
26
  * @param file
@@ -38,6 +48,7 @@ class ConfigLoader {
38
48
  else
39
49
  this.config = newConfig;
40
50
  }
51
+ // noinspection JSUnusedGlobalSymbols
41
52
  /** 将配置项的内容写入到环境中 */
42
53
  write(runtime, compilation) {
43
54
  if (!this.config)
@@ -124,7 +135,7 @@ class ConfigLoader {
124
135
  }
125
136
  if (typeof highValue != typeof lowValue)
126
137
  continue;
127
- if (typeof highValue == 'object') {
138
+ if (typeof highValue == 'object' && !highValue[IndivisibleName] && !lowValue[IndivisibleName]) {
128
139
  mergeHelper(highValue, lowValue);
129
140
  }
130
141
  }
@@ -143,43 +154,77 @@ ConfigLoader.extensions = [
143
154
  ];
144
155
  ConfigLoader.jiti = (0, jiti_1.createJiti)(__filename, {
145
156
  fsCache: false,
146
- moduleCache: false,
147
157
  alias: {
148
- 'swpp-backends': path_1.default.join(__dirname, '..')
158
+ 'swpp-backends': path_1.default.join(__dirname, '..', '..', 'index')
149
159
  }
150
160
  });
151
161
  /** 定义一个通过 `export default` 导出的配置 */
152
162
  function defineConfig(config) {
153
163
  return config;
154
164
  }
155
- exports.defineConfig = defineConfig;
156
165
  /** 定义一个通过 `export const compilationEnv` 导出的配置 */
157
166
  function defineCompilationEnv(config) {
158
167
  return config;
159
168
  }
160
- exports.defineCompilationEnv = defineCompilationEnv;
161
169
  /** 定义一个通过 `export const crossEnv` 导出的配置 */
162
170
  function defineCrossEnv(config) {
163
171
  return config;
164
172
  }
165
- exports.defineCrossEnv = defineCrossEnv;
166
173
  /** 定义一个通过 `export const runtimeDep` 导出的配置 */
167
174
  function defineRuntimeDep(config) {
168
175
  return config;
169
176
  }
170
- exports.defineRuntimeDep = defineRuntimeDep;
171
177
  /** 定义一个通过 `export const crossDep` 导出的配置 */
172
178
  function defineCrossDep(config) {
173
179
  return config;
174
180
  }
175
- exports.defineCrossDep = defineCrossDep;
176
181
  /** 定义一个通过 `export const runtimeCore` 导出的配置 */
177
182
  function defineRuntimeCore(config) {
178
183
  return config;
179
184
  }
180
- exports.defineRuntimeCore = defineRuntimeCore;
181
185
  /** 定义一个通过 `export const runtimeEvent` 导出的配置 */
182
186
  function defineRuntimeEvent(config) {
183
187
  return config;
184
188
  }
185
- exports.defineRuntimeEvent = defineRuntimeEvent;
189
+ /**
190
+ * 定义一个无法分割的对象配置,这对一些强依赖对象内部属性的设置很有用,可以避免对象被错误地拼接。
191
+ *
192
+ * 默认情况下,当定义一个对象配置时,将允许从其它配置文件中合并一部分配置到对象中,比如:
193
+ *
194
+ * ```typescript
195
+ * // 当前配置
196
+ * exampleConfig.obj = {
197
+ * value1: 'hello world'
198
+ * }
199
+ * // 如果还有一个配置文件中也声明了这个配置
200
+ * exampleConfig.obj = {
201
+ * value2: 'hello swpp'
202
+ * }
203
+ * // 最终将合并生成如下配置
204
+ * exampleConfig.obj = {
205
+ * value1: 'hello world',
206
+ * value2: 'hello swpp'
207
+ * }
208
+ * ```
209
+ *
210
+ * 通过该函数,可以禁止 swpp 合并配置时仅选取对象的部分字段,要么全部使用 [value] 的值,要么完全不使用 [value] 的值。
211
+ *
212
+ * 放入到上述例子中,假如两个 obj 任意一个或多个通过 `defineIndivisibleConfig({ xxx: xxx })` 设置,最终的值将取决于两个配置文件的优先级,
213
+ * 若 `value2` 的优先级高将产生:
214
+ *
215
+ * ```typescript
216
+ * // 最终结果
217
+ * exampleConfig.obj = {
218
+ * value2: 'hello swpp'
219
+ * }
220
+ * ```
221
+ */
222
+ function defineIndivisibleConfig(value) {
223
+ Object.defineProperty(value, IndivisibleName, {
224
+ value: true,
225
+ writable: false,
226
+ configurable: false,
227
+ enumerable: false
228
+ });
229
+ return value;
230
+ }
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CompilationEnv = void 0;
29
+ exports.AllowNotFoundEnum = exports.CompilationEnv = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const FileParser_1 = require("../FileParser");
32
32
  const NetworkFileHandler_1 = require("../NetworkFileHandler");
@@ -43,6 +43,16 @@ class CompilationEnv extends KeyValueDatabase_1.KeyValueDatabase {
43
43
  }
44
44
  }
45
45
  exports.CompilationEnv = CompilationEnv;
46
+ /** 拉取版本信息和 tracker 时的 404 等级 */
47
+ var AllowNotFoundEnum;
48
+ (function (AllowNotFoundEnum) {
49
+ /** 允许任意形式的 404,包含 DNS 解析失败 */
50
+ AllowNotFoundEnum[AllowNotFoundEnum["ALLOW_ALL"] = 0] = "ALLOW_ALL";
51
+ /** 允许服务器返回 404 */
52
+ AllowNotFoundEnum[AllowNotFoundEnum["ALLOW_STATUS"] = 1] = "ALLOW_STATUS";
53
+ /** 拒绝任意形式的 404 */
54
+ AllowNotFoundEnum[AllowNotFoundEnum["REJECT_ALL"] = 2] = "REJECT_ALL";
55
+ })(AllowNotFoundEnum || (exports.AllowNotFoundEnum = AllowNotFoundEnum = {}));
46
56
  function buildCommon(_env, crossEnv, crossCode) {
47
57
  const env = _env;
48
58
  return {
@@ -130,6 +140,19 @@ function buildCommon(_env, crossEnv, crossCode) {
130
140
  error: (err) => err?.cause?.code === 'ENOTFOUND'
131
141
  }
132
142
  }),
143
+ ALLOW_NOT_FOUND: (0, KeyValueDatabase_1.buildEnv)({
144
+ default: AllowNotFoundEnum.ALLOW_STATUS,
145
+ checker(value) {
146
+ switch (value) {
147
+ case AllowNotFoundEnum.ALLOW_ALL:
148
+ case AllowNotFoundEnum.ALLOW_STATUS:
149
+ case AllowNotFoundEnum.REJECT_ALL:
150
+ return false;
151
+ default:
152
+ return { value, message: '填写了非法的 ALLOW_NOT_FOUND 值' };
153
+ }
154
+ }
155
+ }),
133
156
  FILE_PARSER: (0, KeyValueDatabase_1.buildEnv)({
134
157
  default: createRegister(env, crossEnv, crossCode)
135
158
  })
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildEnv = exports.KeyValueDatabase = void 0;
3
+ exports.KeyValueDatabase = void 0;
4
+ exports.buildEnv = buildEnv;
4
5
  /** 键值对存储器 */
5
6
  class KeyValueDatabase {
6
7
  constructor(map) {
@@ -73,4 +74,3 @@ exports.KeyValueDatabase = KeyValueDatabase;
73
74
  function buildEnv(env) {
74
75
  return env;
75
76
  }
76
- exports.buildEnv = buildEnv;
@@ -177,7 +177,7 @@ exports.utils = Object.freeze({
177
177
  return `${hours}:${minutes}:${seconds}`;
178
178
  },
179
179
  printError(title, err) {
180
- console.error(`[${this.time()}] [ERR] [SWPP] [${title}]: ${JSON.stringify(err, null, 2)}`);
180
+ console.error(`[${this.time()}] [ERR] [SWPP] [${title}]: `, err);
181
181
  },
182
182
  printInfo(title, info) {
183
183
  console.info(`[${this.time()}] [INFO] [SWPP] [${title}]: ${JSON.stringify(info, null, 2)}`);
@@ -252,5 +252,9 @@ exports.exceptionNames = {
252
252
  /** 空指针 */
253
253
  nullPoint: 'null_point',
254
254
  /** 配置文件已经完成构建 */
255
- configBuilt: 'config_built'
255
+ configBuilt: 'config_built',
256
+ /** 404 错误 */
257
+ notFound: 'not_found',
258
+ /** 未知分类错误 */
259
+ error: 'error'
256
260
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -12,8 +12,8 @@
12
12
  ],
13
13
  "devDependencies": {
14
14
  "@types/fast-html-parser": "^1.0.2",
15
- "@types/node": "^20.4.5",
16
- "typescript": "^5.1.6"
15
+ "@types/node": "^22.0.2",
16
+ "typescript": "^5.5.4"
17
17
  },
18
18
  "dependencies": {
19
19
  "fast-html-parser": "^1.0.1",
package/types/index.d.ts CHANGED
@@ -1,2 +1,31 @@
1
+ import { COMMON_TYPE_COMP_ENV } from './swpp/database/CompilationEnv';
2
+ import { COMMON_TYPE_CROSS_DEP } from './swpp/database/CrossDepCode';
3
+ import { COMMON_TYPE_CROSS_ENV } from './swpp/database/CrossEnv';
4
+ import { COMMON_TYPE_RUNTIME_CORE } from './swpp/database/RuntimeCoreCode';
5
+ import { COMMON_KEY_RUNTIME_DEP } from './swpp/database/RuntimeDepCode';
6
+ import { COMMON_TYPE_RUNTIME_EVENT } from './swpp/database/RuntimeEventCode';
1
7
  /** 版本号 */
2
8
  export declare const version: any;
9
+ export { utils, RuntimeException } from './swpp/untils';
10
+ export { ResourcesScanner, FileUpdateTracker, } from './swpp/ResourcesScanner';
11
+ export { JsonBuilder, UpdateJson, UpdateChangeExp, TrackerHeaderDiff } from './swpp/JsonBuilder';
12
+ export { FileParserRegistry, FileParser, FileMark } from './swpp/FileParser';
13
+ export { SwCompiler, CompilationData, RuntimeData, BrowserVersion } from './swpp/SwCompiler';
14
+ export { NetworkFileHandler, FiniteConcurrencyFetcher } from './swpp/NetworkFileHandler';
15
+ export { ConfigLoader, SwppConfigRuntimeEvent, SwppConfigRuntimeCore, SwppConfigRuntimeDep, SwppConfigCrossDep, SwppConfigCrossEnv, SwppConfigCompilationEnv, SwppConfigTemplate, defineCompilationEnv, defineConfig, defineCrossEnv, defineCrossDep, defineRuntimeDep, defineRuntimeCore, defineRuntimeEvent, defineIndivisibleConfig } from './swpp/config/ConfigLoader';
16
+ export { KeyValueDatabase, DatabaseValue, RuntimeEnvErrorTemplate, RuntimeEnvException } from './swpp/database/KeyValueDatabase';
17
+ export { RuntimeKeyValueDatabase } from './swpp/database/RuntimeKeyValueDatabase';
18
+ export { RuntimeEventCode } from './swpp/database/RuntimeEventCode';
19
+ export { RuntimeCoreCode } from './swpp/database/RuntimeCoreCode';
20
+ export { RuntimeDepCode } from './swpp/database/RuntimeDepCode';
21
+ export { CrossEnv } from './swpp/database/CrossEnv';
22
+ export { CrossDepCode } from './swpp/database/CrossDepCode';
23
+ export { CompilationEnv, AllowNotFoundEnum } from './swpp/database/CompilationEnv';
24
+ export declare namespace SwppType {
25
+ type RuntimeEventCode = COMMON_TYPE_RUNTIME_EVENT;
26
+ type RuntimeCoreCode = COMMON_TYPE_RUNTIME_CORE;
27
+ type RuntimeDepCode = COMMON_KEY_RUNTIME_DEP;
28
+ type CrossEnv = COMMON_TYPE_CROSS_ENV;
29
+ type CrossDep = COMMON_TYPE_CROSS_DEP;
30
+ type CompilationEnv = COMMON_TYPE_COMP_ENV;
31
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as crypto from 'node:crypto';
3
2
  import { CompilationData } from './SwCompiler';
4
3
  export declare class FileParserRegistry {
@@ -64,4 +64,6 @@ export declare class FileUpdateTracker {
64
64
  json(): string;
65
65
  /** 解序列化数据 */
66
66
  static unJson(compilation: CompilationData, jsonStr: string): FileUpdateTracker;
67
+ /** 从网络拉取并解析 tracker */
68
+ static parserJsonFromNetwork(compilation: CompilationData, url: RequestInfo | URL): Promise<FileUpdateTracker>;
67
69
  }
@@ -35,6 +35,40 @@ export declare function defineCrossDep(config: SwppConfigCrossDep): SwppConfigCr
35
35
  export declare function defineRuntimeCore(config: SwppConfigRuntimeCore): SwppConfigRuntimeCore;
36
36
  /** 定义一个通过 `export const runtimeEvent` 导出的配置 */
37
37
  export declare function defineRuntimeEvent(config: SwppConfigRuntimeEvent): SwppConfigRuntimeEvent;
38
+ /**
39
+ * 定义一个无法分割的对象配置,这对一些强依赖对象内部属性的设置很有用,可以避免对象被错误地拼接。
40
+ *
41
+ * 默认情况下,当定义一个对象配置时,将允许从其它配置文件中合并一部分配置到对象中,比如:
42
+ *
43
+ * ```typescript
44
+ * // 当前配置
45
+ * exampleConfig.obj = {
46
+ * value1: 'hello world'
47
+ * }
48
+ * // 如果还有一个配置文件中也声明了这个配置
49
+ * exampleConfig.obj = {
50
+ * value2: 'hello swpp'
51
+ * }
52
+ * // 最终将合并生成如下配置
53
+ * exampleConfig.obj = {
54
+ * value1: 'hello world',
55
+ * value2: 'hello swpp'
56
+ * }
57
+ * ```
58
+ *
59
+ * 通过该函数,可以禁止 swpp 合并配置时仅选取对象的部分字段,要么全部使用 [value] 的值,要么完全不使用 [value] 的值。
60
+ *
61
+ * 放入到上述例子中,假如两个 obj 任意一个或多个通过 `defineIndivisibleConfig({ xxx: xxx })` 设置,最终的值将取决于两个配置文件的优先级,
62
+ * 若 `value2` 的优先级高将产生:
63
+ *
64
+ * ```typescript
65
+ * // 最终结果
66
+ * exampleConfig.obj = {
67
+ * value2: 'hello swpp'
68
+ * }
69
+ * ```
70
+ */
71
+ export declare function defineIndivisibleConfig<T extends Record<string, any>>(value: T): T;
38
72
  type ValueOrReturnValue<T> = T | ((this: CompilationData) => T);
39
73
  /**
40
74
  * SWPP 配置模板
@@ -11,6 +11,15 @@ export type COMMON_TYPE_COMP_ENV = ReturnType<typeof buildCommon>;
11
11
  export declare class CompilationEnv extends KeyValueDatabase<any, COMMON_TYPE_COMP_ENV> {
12
12
  constructor(crossEnv: CrossEnv, crossCode: CrossDepCode);
13
13
  }
14
+ /** 拉取版本信息和 tracker 时的 404 等级 */
15
+ export declare enum AllowNotFoundEnum {
16
+ /** 允许任意形式的 404,包含 DNS 解析失败 */
17
+ ALLOW_ALL = 0,
18
+ /** 允许服务器返回 404 */
19
+ ALLOW_STATUS = 1,
20
+ /** 拒绝任意形式的 404 */
21
+ REJECT_ALL = 2
22
+ }
14
23
  declare function buildCommon(_env: any, crossEnv: CrossEnv, crossCode: CrossDepCode): {
15
24
  readonly DOMAIN_HOST: import("./KeyValueDatabase").DatabaseValue<string>;
16
25
  /** HTML 数量限制 */
@@ -28,6 +37,7 @@ declare function buildCommon(_env: any, crossEnv: CrossEnv, crossCode: CrossDepC
28
37
  response: (response: Response) => boolean;
29
38
  error: (err: any) => boolean;
30
39
  }>;
40
+ readonly ALLOW_NOT_FOUND: import("./KeyValueDatabase").DatabaseValue<AllowNotFoundEnum>;
31
41
  readonly FILE_PARSER: import("./KeyValueDatabase").DatabaseValue<FileParserRegistry>;
32
42
  };
33
43
  export {};
@@ -34,7 +34,7 @@ export declare const utils: Readonly<{
34
34
  */
35
35
  anyToSource(obj: {
36
36
  [p: string]: any;
37
- }, includeEmptyValue?: boolean, writeAsVar?: 'let' | 'const'): string;
37
+ }, includeEmptyValue?: boolean, writeAsVar?: "let" | "const"): string;
38
38
  /** 判断指定链接的 host 是否为指定的 host */
39
39
  isSameHost(path: string, host: string): boolean;
40
40
  /** 计算字符串的哈希值 */
@@ -48,21 +48,21 @@ export declare const utils: Readonly<{
48
48
  * @param obj
49
49
  * @param transfer
50
50
  */
51
- objMap<T_1, R>(obj: {
52
- [key: string]: T_1;
53
- }, transfer: (item: T_1) => R): {
51
+ objMap<T, R>(obj: {
52
+ [key: string]: T;
53
+ }, transfer: (item: T) => R): {
54
54
  [key: string]: R;
55
55
  };
56
56
  /** 深度冻结一个对象 */
57
- deepFreeze<T_2>(obj: T_2): Readonly<T_2>;
57
+ deepFreeze<T>(obj: T): Readonly<T>;
58
58
  /** 二分查找 */
59
- binarySearch<T_3>(array: T_3[], value: T_3, startInclude?: number, endExclude?: number, comparator?: (a: T_3, b: T_3) => number): number;
59
+ binarySearch<T>(array: T[], value: T, startInclude?: number, endExclude?: number, comparator?: (a: T, b: T) => number): number;
60
60
  /**
61
61
  * 在可迭代容器中查找满足指定条件的元素的下标
62
62
  */
63
- findValueInIterable<T_4>(set: Iterable<T_4>, predicate: (item: T_4) => boolean): {
63
+ findValueInIterable<T>(set: Iterable<T>, predicate: (item: T) => boolean): {
64
64
  index: number;
65
- value: T_4;
65
+ value: T;
66
66
  }[];
67
67
  }>;
68
68
  export declare const exceptionNames: {
@@ -80,6 +80,10 @@ export declare const exceptionNames: {
80
80
  readonly nullPoint: "null_point";
81
81
  /** 配置文件已经完成构建 */
82
82
  readonly configBuilt: "config_built";
83
+ /** 404 错误 */
84
+ readonly notFound: "not_found";
85
+ /** 未知分类错误 */
86
+ readonly error: "error";
83
87
  };
84
88
  export interface RuntimeException {
85
89
  /** 报错类型代码 */