surgio 4.0.0-beta.6 → 4.0.0-beta.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/build/generator/artifact.js +19 -50
- package/build/generator/artifact.js.map +1 -1
- package/build/runtime/core.d.ts +20 -0
- package/build/runtime/core.js +176 -0
- package/build/runtime/core.js.map +1 -0
- package/build/runtime/node.js +34 -167
- package/build/runtime/node.js.map +1 -1
- package/build/runtime/provider-error.d.ts +6 -0
- package/build/runtime/provider-error.js +17 -0
- package/build/runtime/provider-error.js.map +1 -0
- package/build/runtime/remote-snippet.d.ts +13 -0
- package/build/runtime/remote-snippet.js +37 -0
- package/build/runtime/remote-snippet.js.map +1 -0
- package/build/utils/remote-snippet.d.ts +1 -1
- package/build/utils/remote-snippet.js +8 -43
- package/build/utils/remote-snippet.js.map +1 -1
- package/build/worker/runtime.js +17 -193
- package/build/worker/runtime.js.map +1 -1
- package/package.json +1 -3
|
@@ -4,7 +4,8 @@ import { logger as defaultLogger } from '@surgio/logger';
|
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { createProvider, getProvider, } from '../provider/index.js';
|
|
6
6
|
import { createArtifactRenderContext, mapConcurrent, mergeObjects, prepareProvider, } from '../runtime/artifact.js';
|
|
7
|
-
import {
|
|
7
|
+
import { withProviderError } from '../runtime/provider-error.js';
|
|
8
|
+
import { getNetworkConcurrency } from '../utils/index.js';
|
|
8
9
|
import { resolveDomain } from '../utils/dns.js';
|
|
9
10
|
import { loadModuleSync } from '../utils/module-loader.js';
|
|
10
11
|
import { ArtifactValidator } from '../validators/index.js';
|
|
@@ -107,59 +108,27 @@ export class Artifact extends EventEmitter {
|
|
|
107
108
|
if (!definition && !fs.existsSync(filePath)) {
|
|
108
109
|
throw new Error(`文件 ${filePath} 不存在`);
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
-
try {
|
|
111
|
+
const provider = await withProviderError({ providerName, providerPath: filePath }, async () => {
|
|
112
112
|
const providerDefinition = definition ?? loadModuleSync(filePath);
|
|
113
|
-
provider = this.options.providerRuntime
|
|
113
|
+
const provider = this.options.providerRuntime
|
|
114
114
|
? await createProvider(providerName, providerDefinition, this.options.providerRuntime)
|
|
115
115
|
: await getProvider(providerName, providerDefinition);
|
|
116
116
|
this.providerMap.set(providerName, provider);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
let result;
|
|
134
|
-
try {
|
|
135
|
-
result = await prepareProvider({
|
|
136
|
-
provider,
|
|
137
|
-
providerName,
|
|
138
|
-
providerPath: filePath,
|
|
139
|
-
params: this.getMergedCustomParams(getNodeListParams),
|
|
140
|
-
config,
|
|
141
|
-
concurrency: getNetworkConcurrency(),
|
|
142
|
-
resolveDomain,
|
|
143
|
-
logger: this.options.logger ??
|
|
144
|
-
this.options.providerRuntime?.logger ??
|
|
145
|
-
defaultLogger,
|
|
146
|
-
providerRuntime: this.options.providerRuntime,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
catch (err) /* istanbul ignore next -- @preserve */ {
|
|
150
|
-
if (isSurgioError(err)) {
|
|
151
|
-
err.providerName = providerName;
|
|
152
|
-
err.providerPath = filePath;
|
|
153
|
-
throw err;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
throw new SurgioError(isError(err) ? err.message : '处理 Provider 失败', {
|
|
157
|
-
cause: err,
|
|
158
|
-
providerName,
|
|
159
|
-
providerPath: filePath,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
117
|
+
return provider;
|
|
118
|
+
});
|
|
119
|
+
const result = await withProviderError({ providerName, providerPath: filePath }, () => prepareProvider({
|
|
120
|
+
provider,
|
|
121
|
+
providerName,
|
|
122
|
+
providerPath: filePath,
|
|
123
|
+
params: this.getMergedCustomParams(getNodeListParams),
|
|
124
|
+
config,
|
|
125
|
+
concurrency: getNetworkConcurrency(),
|
|
126
|
+
resolveDomain,
|
|
127
|
+
logger: this.options.logger ??
|
|
128
|
+
this.options.providerRuntime?.logger ??
|
|
129
|
+
defaultLogger,
|
|
130
|
+
providerRuntime: this.options.providerRuntime,
|
|
131
|
+
}));
|
|
163
132
|
const { nodeList: nodeConfigList, subscriptionUserInfo } = result;
|
|
164
133
|
this.nodeConfigListMap.set(providerName, nodeConfigList);
|
|
165
134
|
// Filter 仅使用第一个 Provider 中的定义
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifact.js","sourceRoot":"","sources":["../../src/generator/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,EAEL,cAAc,EACd,WAAW,GAEZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"artifact.js","sourceRoot":"","sources":["../../src/generator/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,EAEL,cAAc,EACd,WAAW,GAEZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,wBAAw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0DAA0D;QAC1D,IAAI,oBAAoB,EAAE,CAAC;YACzB,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAA;YAEpE,IACE,IAAI,CAAC,QAAQ,CAAC,4BAA4B;gBAC1C,YAAY,KAAK,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAC3D,CAAC;gBACD,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;YAClD,CAAC;iBAAM,IAAI,YAAY,KAAK,gBAAgB,EAAE,CAAC;gBAC7C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;YAClD,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAA;QAEnB,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,YAAY;YACZ,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ProjectProviderDefinition } from '../project/types.js';
|
|
2
|
+
import type { CommandConfigAfterNormalize, RemoteSnippet } from '../types.js';
|
|
3
|
+
import type { CacheKeyScope } from './cache-key.js';
|
|
4
|
+
import type { RuntimeOptions, SurgioRuntime } from './public.js';
|
|
5
|
+
import type { Renderer } from './renderer.js';
|
|
6
|
+
export type RuntimeConfig = CommandConfigAfterNormalize & {
|
|
7
|
+
readonly publicUrl: string;
|
|
8
|
+
readonly urlBase: string;
|
|
9
|
+
};
|
|
10
|
+
/** 平台 adapter 只需提供配置来源、Provider 查找、本地片段和渲染器。 */
|
|
11
|
+
export interface RuntimePlatform {
|
|
12
|
+
readonly config: RuntimeConfig;
|
|
13
|
+
readonly version: string;
|
|
14
|
+
readonly renderer: Renderer;
|
|
15
|
+
readonly cacheScope: CacheKeyScope;
|
|
16
|
+
listProviders(): ReadonlyArray<string>;
|
|
17
|
+
getProviderDefinition(name: string): ProjectProviderDefinition | undefined;
|
|
18
|
+
loadSnippet(name: string): RemoteSnippet;
|
|
19
|
+
}
|
|
20
|
+
export declare const createRuntimeCore: (platform: RuntimePlatform, options: RuntimeOptions) => SurgioRuntime;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { logger as defaultLogger } from '@surgio/logger';
|
|
2
|
+
import { createProvider } from '../provider/create-provider.js';
|
|
3
|
+
import { ArtifactValidator } from '../validators/index.js';
|
|
4
|
+
import { createArtifactRenderContext, mapConcurrent, mergeObjects, prepareProvider, } from './artifact.js';
|
|
5
|
+
import { buildRenderedArtifactCacheKey } from './cache-key.js';
|
|
6
|
+
import { createDefaultDomainResolver } from './dns.js';
|
|
7
|
+
import { formatProviderNodes } from './format.js';
|
|
8
|
+
import { createHttpClient } from './http-client.js';
|
|
9
|
+
import { withProviderError } from './provider-error.js';
|
|
10
|
+
import { loadRemoteSnippets } from './remote-snippet.js';
|
|
11
|
+
export const createRuntimeCore = (platform, options) => {
|
|
12
|
+
const { config, renderer } = platform;
|
|
13
|
+
const { cache } = options;
|
|
14
|
+
const logger = options.logger ?? defaultLogger;
|
|
15
|
+
const network = options.network ?? {};
|
|
16
|
+
const concurrency = network.concurrency ?? 5;
|
|
17
|
+
const resolveDomain = options.resolveDomain ?? createDefaultDomainResolver();
|
|
18
|
+
const providerRuntime = {
|
|
19
|
+
cache,
|
|
20
|
+
config,
|
|
21
|
+
httpClient: createHttpClient({
|
|
22
|
+
fetch: options.fetch,
|
|
23
|
+
retry: network.retry ?? 1,
|
|
24
|
+
timeout: network.timeout ?? 10_000,
|
|
25
|
+
}),
|
|
26
|
+
logger,
|
|
27
|
+
providerCacheTtl: network.providerCacheTtl ?? 10 * 60_000,
|
|
28
|
+
version: platform.version,
|
|
29
|
+
};
|
|
30
|
+
const getArtifact = (name) => {
|
|
31
|
+
const artifact = config.artifacts.find((item) => item.name === name);
|
|
32
|
+
if (!artifact)
|
|
33
|
+
throw new Error(`Artifact ${name} 不存在`);
|
|
34
|
+
return artifact;
|
|
35
|
+
};
|
|
36
|
+
const getProvider = async (name) => {
|
|
37
|
+
const definition = platform.getProviderDefinition(name);
|
|
38
|
+
return definition
|
|
39
|
+
? createProvider(name, definition, providerRuntime)
|
|
40
|
+
: undefined;
|
|
41
|
+
};
|
|
42
|
+
const requireProvider = async (name) => {
|
|
43
|
+
const provider = await getProvider(name);
|
|
44
|
+
if (!provider)
|
|
45
|
+
throw new Error(`Provider ${name} 不存在`);
|
|
46
|
+
return provider;
|
|
47
|
+
};
|
|
48
|
+
const loadProviders = (artifact, renderOptions) => mapConcurrent([artifact.provider, ...(artifact.combineProviders ?? [])], concurrency, (providerName) => withProviderError({ providerName }, async () => prepareProvider({
|
|
49
|
+
provider: await requireProvider(providerName),
|
|
50
|
+
providerName,
|
|
51
|
+
params: mergeObjects(config.customParams, artifact.customParams, renderOptions.getNodeListParams),
|
|
52
|
+
config,
|
|
53
|
+
concurrency,
|
|
54
|
+
resolveDomain: (domain) => resolveDomain(domain, network.timeout),
|
|
55
|
+
logger,
|
|
56
|
+
providerRuntime,
|
|
57
|
+
})));
|
|
58
|
+
const renderFresh = async (artifact, renderOptions) => {
|
|
59
|
+
const providerResults = await loadProviders(artifact, renderOptions);
|
|
60
|
+
const nodeList = providerResults.flatMap((result) => result.nodeList);
|
|
61
|
+
const mainProvider = providerResults.find((result) => result.provider.name === artifact.provider).provider;
|
|
62
|
+
const customFilters = {
|
|
63
|
+
...config.customFilters,
|
|
64
|
+
...mainProvider.config.customFilters,
|
|
65
|
+
...artifact.customFilters,
|
|
66
|
+
};
|
|
67
|
+
const subscriptionUserInfoMap = Object.fromEntries(providerResults.flatMap((result) => result.subscriptionUserInfo
|
|
68
|
+
? [[result.provider.name, result.subscriptionUserInfo]]
|
|
69
|
+
: []));
|
|
70
|
+
const subscriptionUserInfo = subscriptionUserInfoMap[artifact.subscriptionUserInfoProvider ?? artifact.provider];
|
|
71
|
+
const selectedFilter = typeof renderOptions.filter === 'string'
|
|
72
|
+
? customFilters[renderOptions.filter]
|
|
73
|
+
: renderOptions.filter;
|
|
74
|
+
if (typeof renderOptions.filter === 'string' && !selectedFilter) {
|
|
75
|
+
throw new Error(`Filter ${renderOptions.filter} 不存在`);
|
|
76
|
+
}
|
|
77
|
+
if (renderOptions.format) {
|
|
78
|
+
const body = formatProviderNodes(renderOptions.format, nodeList, selectedFilter, { logger });
|
|
79
|
+
return { body, subscriptionUserInfo, subscriptionUserInfoMap };
|
|
80
|
+
}
|
|
81
|
+
const renderContext = createArtifactRenderContext({
|
|
82
|
+
artifact,
|
|
83
|
+
config,
|
|
84
|
+
nodeList,
|
|
85
|
+
mainProvider,
|
|
86
|
+
customFilters,
|
|
87
|
+
customParams: mergeObjects(config.customParams, artifact.customParams, renderOptions.customParams),
|
|
88
|
+
remoteSnippetList: await loadRemoteSnippets(config.remoteSnippets ?? [], {
|
|
89
|
+
cache,
|
|
90
|
+
cacheTtl: network.remoteSnippetCacheTtl ?? 12 * 60 * 60_000,
|
|
91
|
+
concurrency,
|
|
92
|
+
httpClient: providerRuntime.httpClient,
|
|
93
|
+
logger,
|
|
94
|
+
}),
|
|
95
|
+
downloadUrl: renderOptions.downloadUrl,
|
|
96
|
+
loadSnippet: platform.loadSnippet,
|
|
97
|
+
logger,
|
|
98
|
+
});
|
|
99
|
+
const body = renderer.renderArtifact(artifact, renderContext);
|
|
100
|
+
return { body, subscriptionUserInfo, subscriptionUserInfoMap };
|
|
101
|
+
};
|
|
102
|
+
const render = async (artifact, renderOptions = {}) => {
|
|
103
|
+
const cacheKey = buildRenderedArtifactCacheKey(platform.cacheScope, artifact, renderOptions);
|
|
104
|
+
if (!cacheKey.cacheable) {
|
|
105
|
+
logger.debug('Artifact %s 跳过渲染缓存:%s', artifact.name, cacheKey.reason);
|
|
106
|
+
return { ...(await renderFresh(artifact, renderOptions)), artifact };
|
|
107
|
+
}
|
|
108
|
+
const data = await cache.wrap(cacheKey.key, () => renderFresh(artifact, renderOptions), network.artifactCacheTtl ?? 7 * 24 * 60 * 60_000);
|
|
109
|
+
return { ...data, artifact };
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
renderArtifact(name, renderOptions) {
|
|
113
|
+
return render(getArtifact(name), renderOptions);
|
|
114
|
+
},
|
|
115
|
+
renderProviders(renderOptions) {
|
|
116
|
+
const providers = Array.isArray(renderOptions.providers)
|
|
117
|
+
? renderOptions.providers
|
|
118
|
+
: [renderOptions.providers];
|
|
119
|
+
if (!providers.length)
|
|
120
|
+
throw new Error('至少需要一个 Provider');
|
|
121
|
+
const artifact = ArtifactValidator.parse({
|
|
122
|
+
name: `providers:${providers.join(',')}`,
|
|
123
|
+
provider: providers[0],
|
|
124
|
+
combineProviders: providers.slice(1),
|
|
125
|
+
template: renderOptions.template ?? '',
|
|
126
|
+
});
|
|
127
|
+
return render(artifact, {
|
|
128
|
+
...renderOptions,
|
|
129
|
+
format: renderOptions.template
|
|
130
|
+
? renderOptions.format
|
|
131
|
+
: (renderOptions.format ?? 'clash'),
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
async renderTemplate(name, context = {}) {
|
|
135
|
+
return renderer.renderTemplate(name.endsWith('.tpl') ? name : `${name}.tpl`, context);
|
|
136
|
+
},
|
|
137
|
+
listArtifacts() {
|
|
138
|
+
return [...config.artifacts];
|
|
139
|
+
},
|
|
140
|
+
listProviders() {
|
|
141
|
+
return platform.listProviders();
|
|
142
|
+
},
|
|
143
|
+
async getProviderInfo(name) {
|
|
144
|
+
const provider = await getProvider(name);
|
|
145
|
+
if (!provider)
|
|
146
|
+
return undefined;
|
|
147
|
+
return {
|
|
148
|
+
name: provider.name,
|
|
149
|
+
type: provider.type,
|
|
150
|
+
...('url' in provider && typeof provider.url === 'string'
|
|
151
|
+
? { url: provider.url }
|
|
152
|
+
: null),
|
|
153
|
+
supportGetSubscriptionUserInfo: provider.supportGetSubscriptionUserInfo,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
async getProviderSubscription(name, params = {}) {
|
|
157
|
+
const provider = await requireProvider(name);
|
|
158
|
+
return provider.getSubscriptionUserInfo(params);
|
|
159
|
+
},
|
|
160
|
+
getGatewayConfig() {
|
|
161
|
+
return {
|
|
162
|
+
urlBase: config.urlBase,
|
|
163
|
+
publicUrl: config.publicUrl,
|
|
164
|
+
coreVersion: platform.version,
|
|
165
|
+
...config.gateway,
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
resetCache() {
|
|
169
|
+
return cache.reset();
|
|
170
|
+
},
|
|
171
|
+
close() {
|
|
172
|
+
return cache.close();
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/runtime/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,OAAO,EACL,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAmDxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAAyB,EACzB,OAAuB,EACR,EAAE;IACjB,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAA;IACrC,MAAM,EAAE,KAAK,EA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3
|
-
import { logger as nodeLogger } from '@surgio/logger';
|
|
4
3
|
import packageJson from '../../package.json' with { type: 'json' };
|
|
5
4
|
import { unifiedCache } from '../cache/singleton.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ArtifactValidator } from '../validators/index.js';
|
|
9
|
-
import { loadRemoteSnippetList } from '../utils/remote-snippet.js';
|
|
5
|
+
import { createNodeRenderer, loadLocalSnippet } from '../generator/template.js';
|
|
6
|
+
import { resolveDomain } from '../utils/dns.js';
|
|
10
7
|
import { loadModuleSync } from '../utils/module-loader.js';
|
|
11
|
-
import { getRenderedArtifactCacheMaxage } from '../utils/env-flag.js';
|
|
12
|
-
import {
|
|
13
|
-
import { createHttpClient } from './http-client.js';
|
|
14
|
-
import { formatProviderNodes } from './format.js';
|
|
8
|
+
import { getNetworkConcurrency, getRemoteSnippetCacheMaxage, getRenderedArtifactCacheMaxage, } from '../utils/env-flag.js';
|
|
9
|
+
import { createRuntimeCore } from './core.js';
|
|
15
10
|
export const createNodeSurgioRuntime = (project, options = {}) => {
|
|
16
11
|
const config = project.config;
|
|
17
|
-
const cache = options.cache ?? unifiedCache;
|
|
18
|
-
const logger = options.logger ?? nodeLogger;
|
|
19
|
-
const network = options.network ?? {};
|
|
20
|
-
const providerRuntime = {
|
|
21
|
-
cache,
|
|
22
|
-
config,
|
|
23
|
-
httpClient: createHttpClient({
|
|
24
|
-
fetch: options.fetch,
|
|
25
|
-
retry: network.retry ?? 1,
|
|
26
|
-
timeout: network.timeout ?? 10_000,
|
|
27
|
-
}),
|
|
28
|
-
logger,
|
|
29
|
-
providerCacheTtl: network.providerCacheTtl ?? 10 * 60_000,
|
|
30
|
-
version: packageJson.version,
|
|
31
|
-
};
|
|
32
|
-
const renderer = createNodeRenderer(config.templateDir, {
|
|
33
|
-
artifacts: config.artifacts,
|
|
34
|
-
clashCore: config.clashConfig?.clashCore,
|
|
35
|
-
});
|
|
36
|
-
const getArtifact = (name) => {
|
|
37
|
-
const artifact = config.artifacts.find((item) => item.name === name);
|
|
38
|
-
if (!artifact)
|
|
39
|
-
throw new Error(`Artifact ${name} 不存在`);
|
|
40
|
-
return artifact;
|
|
41
|
-
};
|
|
42
12
|
const getProviderDefinition = (name) => {
|
|
43
13
|
const registered = project.providers?.[name];
|
|
44
14
|
if (registered)
|
|
@@ -48,140 +18,37 @@ export const createNodeSurgioRuntime = (project, options = {}) => {
|
|
|
48
18
|
return undefined;
|
|
49
19
|
return loadModuleSync(filename);
|
|
50
20
|
};
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
const listProviders = () => {
|
|
22
|
+
if (project.providers)
|
|
23
|
+
return Object.keys(project.providers);
|
|
24
|
+
if (!fs.existsSync(config.providerDir))
|
|
25
|
+
return [];
|
|
26
|
+
return fs
|
|
27
|
+
.readdirSync(config.providerDir)
|
|
28
|
+
.filter((name) => name.endsWith('.js'))
|
|
29
|
+
.map((name) => path.basename(name, '.js'));
|
|
56
30
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
renderer,
|
|
78
|
-
});
|
|
79
|
-
await artifact.init({
|
|
80
|
-
getNodeListParams: renderOptions.getNodeListParams,
|
|
81
|
-
});
|
|
82
|
-
const mainProvider = artifact.providerMap.get(artifact.artifact.provider);
|
|
83
|
-
if (!mainProvider)
|
|
84
|
-
throw new Error('Artifact 主 Provider 未初始化');
|
|
85
|
-
const filters = {
|
|
86
|
-
...config.customFilters,
|
|
87
|
-
...mainProvider.config.customFilters,
|
|
88
|
-
...artifact.artifact.customFilters,
|
|
89
|
-
};
|
|
90
|
-
const selectedFilter = typeof renderOptions.filter === 'string'
|
|
91
|
-
? filters[renderOptions.filter]
|
|
92
|
-
: renderOptions.filter;
|
|
93
|
-
if (typeof renderOptions.filter === 'string' && !selectedFilter) {
|
|
94
|
-
throw new Error(`Filter ${renderOptions.filter} 不存在`);
|
|
95
|
-
}
|
|
96
|
-
const body = renderOptions.format
|
|
97
|
-
? formatProviderNodes(renderOptions.format, artifact.nodeList, selectedFilter, { logger })
|
|
98
|
-
: artifact.render(renderOptions.customParams);
|
|
99
|
-
return {
|
|
100
|
-
body,
|
|
101
|
-
subscriptionUserInfo: artifact.subscriptionUserInfo,
|
|
102
|
-
subscriptionUserInfoMap: Object.fromEntries(artifact.subscriptionUserInfoMap),
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
if (!cacheKey.cacheable) {
|
|
106
|
-
logger.debug('Artifact %s 跳过渲染缓存:%s', artifactConfig.name, cacheKey.reason);
|
|
107
|
-
const data = await renderFresh();
|
|
108
|
-
return { ...data, artifact: artifactConfig };
|
|
109
|
-
}
|
|
110
|
-
const data = await cache.wrap(cacheKey.key, renderFresh, network.artifactCacheTtl ?? getRenderedArtifactCacheMaxage());
|
|
111
|
-
return { ...data, artifact: artifactConfig };
|
|
112
|
-
};
|
|
113
|
-
return {
|
|
114
|
-
renderArtifact(name, renderOptions) {
|
|
115
|
-
return render(getArtifact(name), renderOptions);
|
|
116
|
-
},
|
|
117
|
-
renderProviders(renderOptions) {
|
|
118
|
-
const providers = Array.isArray(renderOptions.providers)
|
|
119
|
-
? renderOptions.providers
|
|
120
|
-
: [renderOptions.providers];
|
|
121
|
-
if (!providers.length)
|
|
122
|
-
throw new Error('至少需要一个 Provider');
|
|
123
|
-
const artifact = ArtifactValidator.parse({
|
|
124
|
-
name: `providers:${providers.join(',')}`,
|
|
125
|
-
provider: providers[0],
|
|
126
|
-
combineProviders: providers.slice(1),
|
|
127
|
-
template: renderOptions.template ?? '',
|
|
128
|
-
});
|
|
129
|
-
return render(artifact, {
|
|
130
|
-
...renderOptions,
|
|
131
|
-
format: renderOptions.template
|
|
132
|
-
? renderOptions.format
|
|
133
|
-
: (renderOptions.format ?? 'clash'),
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
async renderTemplate(name, context = {}) {
|
|
137
|
-
return renderer.renderTemplate(name.endsWith('.tpl') ? name : `${name}.tpl`, context);
|
|
138
|
-
},
|
|
139
|
-
listArtifacts() {
|
|
140
|
-
return [...config.artifacts];
|
|
141
|
-
},
|
|
142
|
-
listProviders() {
|
|
143
|
-
if (project.providers)
|
|
144
|
-
return Object.keys(project.providers);
|
|
145
|
-
if (!fs.existsSync(config.providerDir))
|
|
146
|
-
return [];
|
|
147
|
-
return fs
|
|
148
|
-
.readdirSync(config.providerDir)
|
|
149
|
-
.filter((name) => name.endsWith('.js'))
|
|
150
|
-
.map((name) => path.basename(name, '.js'));
|
|
151
|
-
},
|
|
152
|
-
async getProviderInfo(name) {
|
|
153
|
-
const provider = await getProvider(name);
|
|
154
|
-
if (!provider)
|
|
155
|
-
return undefined;
|
|
156
|
-
return {
|
|
157
|
-
name: provider.name,
|
|
158
|
-
type: provider.type,
|
|
159
|
-
...('url' in provider.config && typeof provider.config.url === 'string'
|
|
160
|
-
? { url: provider.config.url }
|
|
161
|
-
: null),
|
|
162
|
-
supportGetSubscriptionUserInfo: provider.supportGetSubscriptionUserInfo,
|
|
163
|
-
};
|
|
164
|
-
},
|
|
165
|
-
async getProviderSubscription(name, params = {}) {
|
|
166
|
-
const provider = await getProvider(name);
|
|
167
|
-
if (!provider)
|
|
168
|
-
throw new Error(`Provider ${name} 不存在`);
|
|
169
|
-
return provider.getSubscriptionUserInfo(params);
|
|
170
|
-
},
|
|
171
|
-
getGatewayConfig() {
|
|
172
|
-
return {
|
|
173
|
-
urlBase: config.urlBase,
|
|
174
|
-
publicUrl: config.publicUrl,
|
|
175
|
-
coreVersion: packageJson.version,
|
|
176
|
-
...config.gateway,
|
|
177
|
-
};
|
|
178
|
-
},
|
|
179
|
-
resetCache() {
|
|
180
|
-
return cache.reset();
|
|
181
|
-
},
|
|
182
|
-
close() {
|
|
183
|
-
return cache.close();
|
|
31
|
+
return createRuntimeCore({
|
|
32
|
+
config,
|
|
33
|
+
version: packageJson.version,
|
|
34
|
+
renderer: createNodeRenderer(config.templateDir, {
|
|
35
|
+
artifacts: config.artifacts,
|
|
36
|
+
clashCore: config.clashConfig?.clashCore,
|
|
37
|
+
}),
|
|
38
|
+
cacheScope: 'node-runtime',
|
|
39
|
+
listProviders,
|
|
40
|
+
getProviderDefinition,
|
|
41
|
+
loadSnippet: (name) => loadLocalSnippet(config.templateDir, name),
|
|
42
|
+
}, {
|
|
43
|
+
...options,
|
|
44
|
+
cache: options.cache ?? unifiedCache,
|
|
45
|
+
resolveDomain: options.resolveDomain ?? resolveDomain,
|
|
46
|
+
network: {
|
|
47
|
+
concurrency: getNetworkConcurrency(),
|
|
48
|
+
artifactCacheTtl: getRenderedArtifactCacheMaxage(),
|
|
49
|
+
remoteSnippetCacheTtl: getRemoteSnippetCacheMaxage(),
|
|
50
|
+
...options.network,
|
|
184
51
|
},
|
|
185
|
-
};
|
|
52
|
+
});
|
|
186
53
|
};
|
|
187
54
|
//# sourceMappingURL=node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/runtime/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/runtime/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,WAAW,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAA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C,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC,CAAA;IAED,OAAO,iBAAiB,CACtB;QACE,MAAM;QACN,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE;YAC/C,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS;SACzC,CAAC;QACF,UAAU,EAAE,cAAc;QAC1B,aAAa;QACb,qBAAqB;QACrB,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC;KAClE,EACD;QACE,GAAG,OAAO;QACV,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,YAAY;QACpC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,aAAa;QACrD,OAAO,EAAE;YACP,WAAW,EAAE,qBAAqB,EAAE;YACpC,gBAAgB,EAAE,8BAA8B,EAAE;YAClD,qBAAqB,EAAE,2BAA2B,EAAE;YACpD,GAAG,OAAO,CAAC,OAAO;SACnB;KACF,CACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isError, isSurgioError, SurgioError } from '../utils/errors.js';
|
|
2
|
+
// The caller names the configured provider entry. Its name and path replace
|
|
3
|
+
// any metadata set by nested providers.
|
|
4
|
+
export const withProviderError = async (context, task) => {
|
|
5
|
+
try {
|
|
6
|
+
return await task();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (isSurgioError(error)) {
|
|
10
|
+
error.providerName = context.providerName;
|
|
11
|
+
error.providerPath = context.providerPath;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
throw new SurgioError(isError(error) ? error.message : '处理 Provider 失败', { cause: error, ...context });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=provider-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-error.js","sourceRoot":"","sources":["../../src/runtime/provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAOxE,4EAA4E;AAC5E,wCAAwC;AACxC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,OAA6B,EAC7B,IAAsB,EACV,EAAE;IACd,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAA;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;YACzC,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;YACzC,MAAM,KAAK,CAAA;QACb,CAAC;QACD,MAAM,IAAI,WAAW,CACnB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,EACjD,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAC7B,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Logger } from '@surgio/logger';
|
|
2
|
+
import type { TtlCache } from '../cache/core.js';
|
|
3
|
+
import type { RemoteSnippet, RemoteSnippetConfig } from '../types.js';
|
|
4
|
+
import type { RuntimeHttpClient } from './types.js';
|
|
5
|
+
interface RemoteSnippetOptions {
|
|
6
|
+
readonly cache: Pick<TtlCache, 'wrap'>;
|
|
7
|
+
readonly cacheTtl: number;
|
|
8
|
+
readonly concurrency: number;
|
|
9
|
+
readonly httpClient: RuntimeHttpClient;
|
|
10
|
+
readonly logger: Logger;
|
|
11
|
+
}
|
|
12
|
+
export declare const loadRemoteSnippets: (configs: ReadonlyArray<RemoteSnippetConfig>, options: RemoteSnippetOptions) => Promise<ReadonlyArray<RemoteSnippet>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CACHE_KEYS } from '../constant/index.js';
|
|
2
|
+
import { toMD5 } from '../utils/portable.js';
|
|
3
|
+
import { mapConcurrent } from './artifact.js';
|
|
4
|
+
import { addProxyToRuleSet } from './ruleset.js';
|
|
5
|
+
import { parseRestrictedSnippet } from './snippet-interpreter.js';
|
|
6
|
+
export const loadRemoteSnippets = (configs, options) => {
|
|
7
|
+
const { cache, cacheTtl, concurrency, httpClient, logger } = options;
|
|
8
|
+
const download = async (url) => {
|
|
9
|
+
try {
|
|
10
|
+
const response = await httpClient.get(url);
|
|
11
|
+
logger.info(`远程片段下载成功:${url}`);
|
|
12
|
+
return response.body;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error(`远程片段下载失败:${url}`);
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const load = (url) => cache.wrap(`${CACHE_KEYS.RemoteSnippets}:${toMD5(url)}`, () => download(url), cacheTtl);
|
|
20
|
+
return mapConcurrent(configs, concurrency, async (config) => {
|
|
21
|
+
const text = await load(config.url);
|
|
22
|
+
let macro;
|
|
23
|
+
return {
|
|
24
|
+
name: config.name,
|
|
25
|
+
url: config.url,
|
|
26
|
+
text,
|
|
27
|
+
main: (...args) => {
|
|
28
|
+
if (config.surgioSnippet) {
|
|
29
|
+
macro ??= parseRestrictedSnippet(text);
|
|
30
|
+
return macro.render(args);
|
|
31
|
+
}
|
|
32
|
+
return addProxyToRuleSet(text, args[0]);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=remote-snippet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-snippet.js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,GAAG,CAAC,CAAA;QACnC,IAAI,KAAyC,CAAA;QAE7C,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,IAAI;YACJ,IAAI,EAAE,CAAC,GAAG,IAAc,EAAE,EAAE;gBAC1B,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;oBACzB,KAAK,KAAK,sBAAsB,CAAC,IAAI,CAAC,CAAA;oBACtC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBAC3B,CAAC;gBACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YACzC,CAAC;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import type { Logger } from '@surgio/logger';
|
|
|
3
3
|
import type { TtlCache } from '../cache/core.js';
|
|
4
4
|
import type { RuntimeHttpClient } from '../runtime/types.js';
|
|
5
5
|
export interface RemoteSnippetRuntimeOptions {
|
|
6
|
-
readonly cache?: Pick<TtlCache, '
|
|
6
|
+
readonly cache?: Pick<TtlCache, 'wrap'>;
|
|
7
7
|
readonly cacheTtl?: number;
|
|
8
8
|
readonly concurrency?: number;
|
|
9
9
|
readonly httpClient?: RuntimeHttpClient;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import Bluebird from 'bluebird';
|
|
2
1
|
import { logger } from '@surgio/logger';
|
|
3
|
-
import ms from 'ms';
|
|
4
2
|
import { unifiedCache } from '../cache/singleton.js';
|
|
5
|
-
import { CACHE_KEYS } from '../constant/index.js';
|
|
6
3
|
import { parseRestrictedSnippet, renderRestrictedSnippet, } from '../runtime/snippet-interpreter.js';
|
|
7
4
|
import { addProxyToRuleSet } from '../runtime/ruleset.js';
|
|
8
5
|
import { httpClient } from '../runtime/http-client.js';
|
|
6
|
+
import { loadRemoteSnippets } from '../runtime/remote-snippet.js';
|
|
9
7
|
import { getNetworkConcurrency, getRemoteSnippetCacheMaxage, } from './env-flag.js';
|
|
10
|
-
import { toMD5 } from './portable.js';
|
|
11
8
|
export const parseMacro = (snippet) => {
|
|
12
9
|
try {
|
|
13
10
|
return {
|
|
@@ -24,46 +21,14 @@ export const renderSurgioSnippet = (str, args) => {
|
|
|
24
21
|
return renderRestrictedSnippet(str, args);
|
|
25
22
|
};
|
|
26
23
|
export const loadRemoteSnippetList = async (remoteSnippetList, cacheSnippet = true, runtime = {}) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const data = await client.get(url);
|
|
33
|
-
runtimeLogger.info(`远程片段下载成功:${url}`);
|
|
34
|
-
return data.body;
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
runtimeLogger.error(`远程片段下载失败:${url}`);
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return Bluebird.map(remoteSnippetList, async (item) => {
|
|
42
|
-
const fileMd5 = toMD5(item.url);
|
|
43
|
-
const isSurgioSnippet = item.surgioSnippet;
|
|
44
|
-
const cacheKey = `${CACHE_KEYS.RemoteSnippets}:${fileMd5}`;
|
|
45
|
-
let snippet = await cache.get(cacheKey);
|
|
46
|
-
if (snippet === undefined) {
|
|
47
|
-
snippet = await load(item.url);
|
|
48
|
-
await cache.set(cacheKey, snippet, cacheSnippet
|
|
49
|
-
? (runtime.cacheTtl ?? getRemoteSnippetCacheMaxage())
|
|
50
|
-
: ms('1m'));
|
|
51
|
-
}
|
|
52
|
-
let macro;
|
|
53
|
-
return {
|
|
54
|
-
main: (...args) => {
|
|
55
|
-
if (isSurgioSnippet) {
|
|
56
|
-
macro ??= parseRestrictedSnippet(snippet);
|
|
57
|
-
return macro.render(args);
|
|
58
|
-
}
|
|
59
|
-
return addProxyToSurgeRuleSet(snippet, args[0]);
|
|
60
|
-
},
|
|
61
|
-
name: item.name,
|
|
62
|
-
url: item.url,
|
|
63
|
-
text: snippet, // 原始内容
|
|
64
|
-
};
|
|
65
|
-
}, {
|
|
24
|
+
return loadRemoteSnippets(remoteSnippetList, {
|
|
25
|
+
cache: runtime.cache ?? unifiedCache,
|
|
26
|
+
cacheTtl: cacheSnippet
|
|
27
|
+
? (runtime.cacheTtl ?? getRemoteSnippetCacheMaxage())
|
|
28
|
+
: 60_000,
|
|
66
29
|
concurrency: runtime.concurrency ?? getNetworkConcurrency(),
|
|
30
|
+
httpClient: runtime.httpClient ?? httpClient,
|
|
31
|
+
logger: runtime.logger ?? logger,
|
|
67
32
|
});
|
|
68
33
|
};
|
|
69
34
|
//# sourceMappingURL=remote-snippet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-snippet.js","sourceRoot":"","sources":["../../src/utils/remote-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"remote-snippet.js","sourceRoot":"","sources":["../../src/utils/remote-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,EACL,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,eAAe,CAAA;AActB,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAAe,EAIf,EAAE;IACF,IAAI,CAAC;QACH,OAAO;YACL,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,CAAC,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;SAC1D,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACjD,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAW,EACX,SAAkB,EACV,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAE,IAAc,EAAU,EAAE;IACzE,OAAO,uBAAuB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,iBAAqD,EACrD,YAAY,GAAG,IAAI,EACnB,OAAO,GAAgC,EAAE,EACF,EAAE;IACzC,OAAO,kBAAkB,CAAC,iBAAiB,EAAE;QAC3C,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,YAAY;QACpC,QAAQ,EAAE,YAAY;YACpB,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,2BAA2B,EAAE,CAAC;YACrD,CAAC,CAAC,MAAM;QACV,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,qBAAqB,EAAE;QAC3D,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,UAAU;QAC5C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,MAAM;KACjC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/build/worker/runtime.js
CHANGED
|
@@ -1,213 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CACHE_KEYS } from '../constant/index.js';
|
|
3
|
-
import { createProvider } from '../provider/create-provider.js';
|
|
4
|
-
import { buildRenderedArtifactCacheKey } from '../runtime/cache-key.js';
|
|
5
|
-
import { createArtifactRenderContext, mapConcurrent, mergeObjects, prepareProvider, } from '../runtime/artifact.js';
|
|
6
|
-
import { createDefaultDomainResolver } from '../runtime/dns.js';
|
|
7
|
-
import { createHttpClient } from '../runtime/http-client.js';
|
|
1
|
+
import { createRuntimeCore } from '../runtime/core.js';
|
|
8
2
|
import { addProxyToRuleSet } from '../runtime/ruleset.js';
|
|
9
|
-
import { renderRestrictedSnippet } from '../runtime/snippet-interpreter.js';
|
|
10
|
-
import { formatProviderNodes } from '../runtime/format.js';
|
|
11
3
|
import { addFlagMap } from '../utils/flag.js';
|
|
12
|
-
import { toMD5 } from '../utils/portable.js';
|
|
13
|
-
import { ArtifactValidator } from '../validators/index.js';
|
|
14
4
|
import { normalizeWorkerConfig } from './normalize-config.js';
|
|
15
5
|
import { createPrecompiledRenderer } from './template-engine.js';
|
|
16
6
|
export const createSurgioRuntime = (manifest, options) => {
|
|
17
7
|
if (!options?.cache)
|
|
18
8
|
throw new Error('Worker runtime 必须注入 cache');
|
|
19
9
|
const config = normalizeWorkerConfig(manifest.config);
|
|
20
|
-
const logger = options.logger ?? defaultLogger;
|
|
21
|
-
const network = options.network ?? {};
|
|
22
|
-
const concurrency = network.concurrency ?? 5;
|
|
23
|
-
const resolveDomain = options.resolveDomain ?? createDefaultDomainResolver();
|
|
24
10
|
for (const [emoji, names] of Object.entries(config.flags ?? {})) {
|
|
25
11
|
for (const name of Array.isArray(names) ? names : [names]) {
|
|
26
12
|
addFlagMap(name, emoji);
|
|
27
13
|
}
|
|
28
14
|
}
|
|
29
|
-
|
|
30
|
-
cache: options.cache,
|
|
15
|
+
return createRuntimeCore({
|
|
31
16
|
config,
|
|
32
|
-
httpClient: createHttpClient({
|
|
33
|
-
fetch: options.fetch,
|
|
34
|
-
retry: network.retry ?? 1,
|
|
35
|
-
timeout: network.timeout ?? 10_000,
|
|
36
|
-
}),
|
|
37
|
-
logger,
|
|
38
|
-
providerCacheTtl: network.providerCacheTtl ?? 10 * 60_000,
|
|
39
17
|
version: manifest.surgioVersion,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const getProvider = async (name) => {
|
|
51
|
-
const definition = manifest.providers[name];
|
|
52
|
-
if (!definition)
|
|
53
|
-
throw new Error(`Provider ${name} 未注册`);
|
|
54
|
-
return createProvider(name, definition, providerRuntime);
|
|
55
|
-
};
|
|
56
|
-
const loadRemoteSnippets = async () => mapConcurrent(config.remoteSnippets ?? [], concurrency, async (snippetConfig) => {
|
|
57
|
-
const cacheKey = `${CACHE_KEYS.RemoteSnippets}:${toMD5(snippetConfig.url)}`;
|
|
58
|
-
const text = await options.cache.wrap(cacheKey, async () => {
|
|
59
|
-
const response = await providerRuntime.httpClient.get(snippetConfig.url);
|
|
60
|
-
logger.info('远程片段下载成功:%s', snippetConfig.url);
|
|
61
|
-
return response.body;
|
|
62
|
-
}, network.remoteSnippetCacheTtl ?? 12 * 60 * 60_000);
|
|
63
|
-
return {
|
|
64
|
-
name: snippetConfig.name,
|
|
65
|
-
url: snippetConfig.url,
|
|
66
|
-
text,
|
|
67
|
-
main: (...args) => snippetConfig.surgioSnippet
|
|
68
|
-
? renderRestrictedSnippet(text, args)
|
|
69
|
-
: addProxyToRuleSet(text, args[0]),
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
const render = async (artifact, renderOptions = {}) => {
|
|
73
|
-
const cacheKey = buildRenderedArtifactCacheKey('worker', artifact, renderOptions);
|
|
74
|
-
const renderFresh = async () => {
|
|
75
|
-
const providerNames = [
|
|
76
|
-
artifact.provider,
|
|
77
|
-
...(artifact.combineProviders ?? []),
|
|
78
|
-
];
|
|
79
|
-
const customParams = mergeObjects(config.customParams, artifact.customParams, renderOptions.customParams);
|
|
80
|
-
const providerResults = await mapConcurrent(providerNames, concurrency, async (providerName) => prepareProvider({
|
|
81
|
-
provider: await getProvider(providerName),
|
|
82
|
-
providerName,
|
|
83
|
-
params: mergeObjects(config.customParams, artifact.customParams, renderOptions.getNodeListParams),
|
|
84
|
-
config,
|
|
85
|
-
concurrency,
|
|
86
|
-
resolveDomain: (domain) => resolveDomain(domain, network.timeout),
|
|
87
|
-
logger,
|
|
88
|
-
providerRuntime,
|
|
89
|
-
}));
|
|
90
|
-
const nodeList = providerResults.flatMap((result) => result.nodeList);
|
|
91
|
-
const mainProvider = providerResults.find((result) => result.provider.name === artifact.provider).provider;
|
|
92
|
-
const customFilters = {
|
|
93
|
-
...config.customFilters,
|
|
94
|
-
...mainProvider.config.customFilters,
|
|
95
|
-
...artifact.customFilters,
|
|
96
|
-
};
|
|
97
|
-
const subscriptionUserInfoMap = Object.fromEntries(providerResults.flatMap((result) => result.subscriptionUserInfo
|
|
98
|
-
? [[result.provider.name, result.subscriptionUserInfo]]
|
|
99
|
-
: []));
|
|
100
|
-
const subscriptionProvider = artifact.subscriptionUserInfoProvider ?? artifact.provider;
|
|
101
|
-
const subscriptionUserInfo = subscriptionUserInfoMap[subscriptionProvider];
|
|
102
|
-
const remoteSnippetList = await loadRemoteSnippets();
|
|
103
|
-
const renderContext = createArtifactRenderContext({
|
|
104
|
-
artifact,
|
|
105
|
-
config,
|
|
106
|
-
nodeList,
|
|
107
|
-
mainProvider,
|
|
108
|
-
customFilters,
|
|
109
|
-
customParams,
|
|
110
|
-
remoteSnippetList,
|
|
111
|
-
downloadUrl: renderOptions.downloadUrl,
|
|
112
|
-
loadSnippet: (name) => {
|
|
113
|
-
const text = manifest.rawTemplates[name];
|
|
114
|
-
if (text === undefined)
|
|
115
|
-
throw new Error(`本地片段 ${name} 不存在`);
|
|
116
|
-
return {
|
|
117
|
-
name,
|
|
118
|
-
url: name,
|
|
119
|
-
text,
|
|
120
|
-
main: (rule) => addProxyToRuleSet(text, rule),
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
logger,
|
|
124
|
-
});
|
|
125
|
-
const selectedFilter = typeof renderOptions.filter === 'string'
|
|
126
|
-
? customFilters[renderOptions.filter]
|
|
127
|
-
: renderOptions.filter;
|
|
128
|
-
if (typeof renderOptions.filter === 'string' && !selectedFilter) {
|
|
129
|
-
throw new Error(`Filter ${renderOptions.filter} 不存在`);
|
|
130
|
-
}
|
|
131
|
-
let body;
|
|
132
|
-
if (renderOptions.format) {
|
|
133
|
-
body = formatProviderNodes(renderOptions.format, nodeList, selectedFilter, { logger });
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
body = renderer.renderArtifact(artifact, renderContext);
|
|
137
|
-
}
|
|
138
|
-
return { body, subscriptionUserInfo, subscriptionUserInfoMap };
|
|
139
|
-
};
|
|
140
|
-
if (!cacheKey.cacheable) {
|
|
141
|
-
logger.debug('Artifact %s 跳过渲染缓存:%s', artifact.name, cacheKey.reason);
|
|
142
|
-
const data = await renderFresh();
|
|
143
|
-
return { ...data, artifact };
|
|
144
|
-
}
|
|
145
|
-
const data = await options.cache.wrap(cacheKey.key, renderFresh, network.artifactCacheTtl ?? 7 * 24 * 60 * 60_000);
|
|
146
|
-
return { ...data, artifact };
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
renderArtifact(name, renderOptions) {
|
|
150
|
-
return render(getArtifact(name), renderOptions);
|
|
151
|
-
},
|
|
152
|
-
renderProviders(renderOptions) {
|
|
153
|
-
const providers = Array.isArray(renderOptions.providers)
|
|
154
|
-
? renderOptions.providers
|
|
155
|
-
: [renderOptions.providers];
|
|
156
|
-
if (!providers.length)
|
|
157
|
-
throw new Error('至少需要一个 Provider');
|
|
158
|
-
const artifact = ArtifactValidator.parse({
|
|
159
|
-
name: `providers:${providers.join(',')}`,
|
|
160
|
-
provider: providers[0],
|
|
161
|
-
combineProviders: providers.slice(1),
|
|
162
|
-
template: renderOptions.template ?? '',
|
|
163
|
-
});
|
|
164
|
-
return render(artifact, {
|
|
165
|
-
...renderOptions,
|
|
166
|
-
format: renderOptions.template
|
|
167
|
-
? renderOptions.format
|
|
168
|
-
: (renderOptions.format ?? 'clash'),
|
|
169
|
-
});
|
|
170
|
-
},
|
|
171
|
-
async renderTemplate(name, context = {}) {
|
|
172
|
-
return renderer.renderTemplate(name.endsWith('.tpl') ? name : `${name}.tpl`, context);
|
|
173
|
-
},
|
|
174
|
-
listArtifacts() {
|
|
175
|
-
return [...config.artifacts];
|
|
176
|
-
},
|
|
177
|
-
listProviders() {
|
|
178
|
-
return Object.keys(manifest.providers);
|
|
179
|
-
},
|
|
180
|
-
async getProviderInfo(name) {
|
|
181
|
-
if (!manifest.providers[name])
|
|
182
|
-
return undefined;
|
|
183
|
-
const provider = await getProvider(name);
|
|
184
|
-
return {
|
|
185
|
-
name: provider.name,
|
|
186
|
-
type: provider.type,
|
|
187
|
-
...('url' in provider.config && typeof provider.config.url === 'string'
|
|
188
|
-
? { url: provider.config.url }
|
|
189
|
-
: null),
|
|
190
|
-
supportGetSubscriptionUserInfo: provider.supportGetSubscriptionUserInfo,
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
async getProviderSubscription(name, params = {}) {
|
|
194
|
-
const provider = await getProvider(name);
|
|
195
|
-
return provider.getSubscriptionUserInfo(params);
|
|
196
|
-
},
|
|
197
|
-
getGatewayConfig() {
|
|
18
|
+
renderer: createPrecompiledRenderer(manifest, {
|
|
19
|
+
clashCore: config.clashConfig?.clashCore,
|
|
20
|
+
}),
|
|
21
|
+
cacheScope: 'worker',
|
|
22
|
+
listProviders: () => Object.keys(manifest.providers),
|
|
23
|
+
getProviderDefinition: (name) => manifest.providers[name],
|
|
24
|
+
loadSnippet: (name) => {
|
|
25
|
+
const text = manifest.rawTemplates[name];
|
|
26
|
+
if (text === undefined)
|
|
27
|
+
throw new Error(`本地片段 ${name} 不存在`);
|
|
198
28
|
return {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
29
|
+
name,
|
|
30
|
+
url: name,
|
|
31
|
+
text,
|
|
32
|
+
main: (rule) => addProxyToRuleSet(text, rule),
|
|
203
33
|
};
|
|
204
34
|
},
|
|
205
|
-
|
|
206
|
-
return options.cache.reset();
|
|
207
|
-
},
|
|
208
|
-
close() {
|
|
209
|
-
return options.cache.close();
|
|
210
|
-
},
|
|
211
|
-
};
|
|
35
|
+
}, options);
|
|
212
36
|
};
|
|
213
37
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/worker/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/worker/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAShE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAAwB,EACxB,OAA6B,EACd,EAAE;IACjB,IAAI,CAAC,OAAO,EAAE,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAEjE,MAAM,MAAM,GAAG,qBAAqB,CAClC,QAAQ,CAAC,MAAsC,CAChD,CAAA;IACD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QAChE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1D,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,OAAO,iBAAiB,CACtB;QACE,MAAM;QACN,OAAO,EAAE,QAAQ,CAAC,aAAa;QAC/B,QAAQ,EAAE,yBAAyB,CAAC,QAAQ,EAAE;YAC5C,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS;SACzC,CAAC;QACF,UAAU,EAAE,QAAQ;QACpB,aAAa,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACpD,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC;QACzD,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE;YACpB,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;YACxC,IAAI,IAAI,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAA;YAC3D,OAAO;gBACL,IAAI;gBACJ,GAAG,EAAE,IAAI;gBACT,IAAI;gBACJ,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;aACtD,CAAA;QACH,CAAC;KACF,EACD,OAAO,CACR,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "surgio",
|
|
3
3
|
"description": "Generating rules for Surge, Clash, Quantumult like a PRO",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"types": "./build/index.d.ts",
|
|
@@ -147,7 +147,6 @@
|
|
|
147
147
|
"@surgio/eslint-config-surgio": "3.0.0-beta.0",
|
|
148
148
|
"@surgio/logger": "2.0.0-beta.0",
|
|
149
149
|
"@upstash/redis": "^1.38.2",
|
|
150
|
-
"bluebird": "^3.7.2",
|
|
151
150
|
"bytes": "^3.1.2",
|
|
152
151
|
"chalk": "^6.0.0",
|
|
153
152
|
"change-case": "^5.4.4",
|
|
@@ -188,7 +187,6 @@
|
|
|
188
187
|
"@commitlint/config-angular": "^21.2.2",
|
|
189
188
|
"@eslint/js": "^10.0.1",
|
|
190
189
|
"@oclif/test": "^5.0.0",
|
|
191
|
-
"@types/bluebird": "^3.5.42",
|
|
192
190
|
"@types/bytes": "^3.1.5",
|
|
193
191
|
"@types/debug": "^4.1.13",
|
|
194
192
|
"@types/fs-extra": "^11.0.4",
|