feat(scenarios): export used snippets with a scenario
- list the snippets a scenario uses in the export dialog, checked by default, with the versions the scenario uses - export each selected snippet once per used version (latest and pinned) via the new snippetIds query parameter - resolve used snippets from the exported version's steps - show the scenario version in the export dialog - document the export query parameters - bump version to 1.22.0
This commit is contained in:
1 parent
f43d902297
commit
23fa302b25
13 files changed
+163
-18
No files matched your search
@@ -486,11 +486,18 @@ export class ScenarioService implements OnModuleInit {
|
||||
*/
|
||||
async getUsedSnippets(scenarioId: string): Promise<UsedSnippet[]> {
|
||||
const scenario = await this.findOne(scenarioId);
|
||||
const snippetMap = await this.snippetService.buildSnippetMap();
|
||||
const usedRefs = resolveUsedSnippetAliases(
|
||||
return this.resolveUsedSnippets(
|
||||
scenario.steps.map((s) => s.execCode ?? ""),
|
||||
snippetMap,
|
||||
).map(parseSnippetRef);
|
||||
);
|
||||
}
|
||||
|
||||
private async resolveUsedSnippets(
|
||||
execCodes: string[],
|
||||
): Promise<UsedSnippet[]> {
|
||||
const snippetMap = await this.snippetService.buildSnippetMap();
|
||||
const usedRefs = resolveUsedSnippetAliases(execCodes, snippetMap).map(
|
||||
parseSnippetRef,
|
||||
);
|
||||
if (usedRefs.length === 0) return [];
|
||||
const snippets = await this.snippetService.findByAliases([
|
||||
...new Set(usedRefs.map((r) => r.alias)),
|
||||
@@ -699,6 +706,8 @@ export class ScenarioService implements OnModuleInit {
|
||||
options: {
|
||||
includeEnvironment: boolean;
|
||||
credentialIds: string[];
|
||||
/** Used snippets to include, at every version the scenario uses. */
|
||||
snippetIds?: string[];
|
||||
/** Version to export; defaults to the latest. */
|
||||
version?: number;
|
||||
},
|
||||
@@ -741,6 +750,25 @@ export class ScenarioService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
// Include selected snippets, once per used version (latest or pinned)
|
||||
const snippetIds = options.snippetIds ?? [];
|
||||
if (snippetIds.length > 0) {
|
||||
const used = await this.resolveUsedSnippets(
|
||||
content.steps.map((s) => s.execCode ?? ""),
|
||||
);
|
||||
const seen = new Set<string>();
|
||||
for (const snippet of used) {
|
||||
if (!snippetIds.includes(snippet.id)) continue;
|
||||
const version = snippet.pinnedVersion ?? snippet.version;
|
||||
const key = `${snippet.id}@${version}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
entities.push(
|
||||
await this.snippetService.exportSnippet(snippet, version),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Scenario is always last
|
||||
const allCreds = scenario.scenarioCredentials ?? [];
|
||||
const credentialMappings = allCreds
|
||||
|
||||
Reference in new issue
Block a user