@sns-parse/core 0.5.0-alpha.1 → 0.6.0-alpha.2

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.
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pipeline = void 0;
4
+ exports.ensurePipeline = ensurePipeline;
5
+ exports.runStage = runStage;
6
+ class Pipeline {
7
+ constructor(rt) {
8
+ this.rt = rt;
9
+ this.impls = new Map();
10
+ this.befores = new Map();
11
+ this.afters = new Map();
12
+ }
13
+ before(stage, h) {
14
+ const list = this.befores.get(stage) || [];
15
+ list.push(h);
16
+ this.befores.set(stage, list);
17
+ }
18
+ after(stage, h) {
19
+ const list = this.afters.get(stage) || [];
20
+ list.push(h);
21
+ this.afters.set(stage, list);
22
+ }
23
+ replace(stage, h) {
24
+ this.impls.set(stage, h);
25
+ }
26
+ async run(stage, input) {
27
+ let cur = input;
28
+ for (const h of this.befores.get(stage) || []) {
29
+ const r = await h(cur, this.rt);
30
+ if (r !== undefined)
31
+ cur = r;
32
+ }
33
+ const impl = this.impls.get(stage);
34
+ if (!impl)
35
+ throw new Error(`workflow: 阶段缺少实现: ${stage}`);
36
+ let out = await impl(cur, this.rt);
37
+ for (const h of this.afters.get(stage) || []) {
38
+ const r = await h(out, cur, this.rt);
39
+ if (r !== undefined)
40
+ out = r;
41
+ }
42
+ return out;
43
+ }
44
+ }
45
+ exports.Pipeline = Pipeline;
46
+ /** 取(或懒挂)runtime 的管道;裸 rt 对象也能工作(自动挂默认管道)。 */
47
+ function ensurePipeline(rt) {
48
+ if (rt && rt.pipeline instanceof Pipeline)
49
+ return rt.pipeline;
50
+ const { createDefaultPipeline } = require('./default');
51
+ const p = createDefaultPipeline(rt);
52
+ if (rt)
53
+ rt.pipeline = p;
54
+ return p;
55
+ }
56
+ function runStage(rt, stage, input) {
57
+ return ensurePipeline(rt).run(stage, input);
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sns-parse/core",
3
- "version": "0.5.0-alpha.1+upstream.1.6.7",
3
+ "version": "0.6.0-alpha.2+upstream.1.6.7",
4
4
  "description": "sns-parse 核心:契约、宿主抽象、配置 DSL 与解析引擎(fetcher/parser/翻译/X 原生解析/合并/GIF/TLS 指纹客户端)",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",