@pipelab/core-node 1.0.0-beta.17 → 1.0.0-beta.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @pipelab/core-node
2
2
 
3
+ ## 1.0.0-beta.19
4
+
5
+ ### Patch Changes
6
+
7
+ - sdsd
8
+ - Updated dependencies
9
+ - @pipelab/constants@1.0.0-beta.17
10
+ - @pipelab/shared@1.0.0-beta.15
11
+
12
+ ## 1.0.0-beta.18
13
+
14
+ ### Patch Changes
15
+
16
+ - sd
17
+ - Updated dependencies
18
+ - @pipelab/constants@1.0.0-beta.16
19
+ - @pipelab/shared@1.0.0-beta.14
20
+
3
21
  ## 1.0.0-beta.17
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ import { c as setupSettingsConfigFile } from "./config-CFgGRD9U.mjs";
2
+ export { setupSettingsConfigFile };
@@ -0,0 +1,265 @@
1
+ import path, { dirname, join } from "node:path";
2
+ import { createWriteStream } from "node:fs";
3
+ import fs$1, { mkdir, readdir, stat, writeFile } from "node:fs/promises";
4
+ import { appSettingsMigrator, connectionsMigrator, fileRepoMigrations, savedFileMigrator, useLogger } from "@pipelab/shared";
5
+ import { execa } from "execa";
6
+ import tar from "tar";
7
+ import yauzl from "yauzl";
8
+ import archiver from "archiver";
9
+ import { pipeline } from "node:stream/promises";
10
+ //#region src/utils/fs-extras.ts
11
+ /**
12
+ * Ensures a directory exists and a file is created with default content if missing.
13
+ */
14
+ const ensure = async (filesPath, defaultContent = "{}") => {
15
+ await mkdir(dirname(filesPath), { recursive: true });
16
+ try {
17
+ if ((await stat(filesPath)).size === 0) await writeFile(filesPath, defaultContent);
18
+ } catch {
19
+ await writeFile(filesPath, defaultContent);
20
+ }
21
+ };
22
+ /**
23
+ * Extracts a .tar.gz archive.
24
+ */
25
+ async function extractTarGz(archivePath, destinationDir) {
26
+ await mkdir(destinationDir, { recursive: true });
27
+ await tar.x({
28
+ file: archivePath,
29
+ cwd: destinationDir
30
+ });
31
+ }
32
+ /**
33
+ * Extracts a .zip archive.
34
+ */
35
+ async function extractZip(archivePath, destinationDir) {
36
+ await mkdir(destinationDir, { recursive: true });
37
+ return new Promise((resolve, reject) => {
38
+ yauzl.open(archivePath, { lazyEntries: true }, (err, zipfile) => {
39
+ if (err || !zipfile) return reject(err || /* @__PURE__ */ new Error("Could not open zip file"));
40
+ zipfile.on("error", reject);
41
+ zipfile.readEntry();
42
+ zipfile.on("entry", (entry) => {
43
+ const entryPath = join(destinationDir, entry.fileName);
44
+ if (/\/$/.test(entry.fileName)) mkdir(entryPath, { recursive: true }).then(() => zipfile.readEntry()).catch(reject);
45
+ else mkdir(dirname(entryPath), { recursive: true }).then(() => {
46
+ zipfile.openReadStream(entry, (err, readStream) => {
47
+ if (err || !readStream) return reject(err || /* @__PURE__ */ new Error("Could not open read stream"));
48
+ readStream.on("error", reject);
49
+ const writeStream = createWriteStream(entryPath);
50
+ writeStream.on("error", reject);
51
+ writeStream.on("close", () => zipfile.readEntry());
52
+ readStream.pipe(writeStream);
53
+ });
54
+ }).catch(reject);
55
+ });
56
+ zipfile.on("end", () => resolve());
57
+ });
58
+ });
59
+ }
60
+ /**
61
+ * Zips a folder.
62
+ */
63
+ const zipFolder = async (from, to, log = console.log) => {
64
+ const output = createWriteStream(to);
65
+ const archive = archiver("zip", { zlib: { level: 9 } });
66
+ return new Promise((resolve, reject) => {
67
+ output.on("close", () => {
68
+ log(archive.pointer() + " total bytes");
69
+ resolve(to);
70
+ });
71
+ archive.on("error", reject);
72
+ archive.pipe(output);
73
+ archive.directory(from, false);
74
+ archive.finalize();
75
+ });
76
+ };
77
+ const downloadFile = async (url, localPath, hooks, abortSignal) => {
78
+ const response = await fetch(url, { signal: abortSignal });
79
+ if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);
80
+ const contentLength = response.headers.get("content-length");
81
+ if (!contentLength) throw new Error("Content-Length header is missing");
82
+ const totalSize = parseInt(contentLength, 10);
83
+ let downloadedSize = 0;
84
+ const fileStream = createWriteStream(localPath);
85
+ const progressStream = new TransformStream({ transform(chunk, controller) {
86
+ downloadedSize += chunk.length;
87
+ const progress = downloadedSize / totalSize * 100;
88
+ hooks?.onProgress?.({
89
+ progress,
90
+ downloadedSize
91
+ });
92
+ controller.enqueue(chunk);
93
+ } });
94
+ const readable = response.body?.pipeThrough(progressStream);
95
+ if (!readable) throw new Error("Failed to create a readable stream");
96
+ await pipeline(readable, fileStream);
97
+ };
98
+ const runWithLiveLogs = async (command, args, execaOptions, log, hooks, abortSignal) => {
99
+ const subprocess = execa(command, args, {
100
+ ...execaOptions,
101
+ stdout: "pipe",
102
+ stderr: "pipe",
103
+ stdin: "pipe",
104
+ env: {
105
+ ...process.env,
106
+ ...execaOptions.env,
107
+ TERM: "xterm-256color",
108
+ FORCE_STDERR_LOGGING: "1"
109
+ },
110
+ cancelSignal: abortSignal
111
+ });
112
+ hooks?.onCreated?.(subprocess);
113
+ subprocess.stdout?.on("data", (data) => {
114
+ hooks?.onStdout?.(data.toString(), subprocess);
115
+ });
116
+ subprocess.stderr?.on("data", (data) => {
117
+ hooks?.onStderr?.(data.toString(), subprocess);
118
+ });
119
+ try {
120
+ const { exitCode } = await subprocess;
121
+ hooks?.onExit?.(exitCode ?? 0);
122
+ } catch (error) {
123
+ const code = error.exitCode ?? 1;
124
+ hooks?.onExit?.(code);
125
+ throw new Error(`Command failed with exit code ${code}: ${error.message}`);
126
+ }
127
+ };
128
+ /**
129
+ * Calculates the total size of a directory recursively.
130
+ */
131
+ async function getFolderSize(dirPath) {
132
+ try {
133
+ const ArrayOfPromises = (await readdir(dirPath, { withFileTypes: true })).map(async (file) => {
134
+ const path = join(dirPath, file.name);
135
+ if (file.isDirectory()) try {
136
+ return await getFolderSize(path);
137
+ } catch {
138
+ return 0;
139
+ }
140
+ try {
141
+ const { size } = await stat(path);
142
+ return size;
143
+ } catch {
144
+ return 0;
145
+ }
146
+ });
147
+ return (await Promise.all(ArrayOfPromises)).reduce((acc, size) => acc + size, 0);
148
+ } catch {
149
+ return 0;
150
+ }
151
+ }
152
+ //#endregion
153
+ //#region src/config.ts
154
+ const setupConfigFile = async (filesPath, options) => {
155
+ options.context;
156
+ const parsedPath = path.parse(filesPath);
157
+ const migrator = options.migrator;
158
+ await ensure(filesPath, JSON.stringify(migrator.defaultValue));
159
+ return {
160
+ setConfig: async (config) => {
161
+ const { logger } = useLogger();
162
+ try {
163
+ await fs$1.writeFile(filesPath, JSON.stringify(config));
164
+ return true;
165
+ } catch (e) {
166
+ logger().error(`Error saving config ${parsedPath.name}:`, e);
167
+ return false;
168
+ }
169
+ },
170
+ getConfig: async () => {
171
+ const { logger } = useLogger();
172
+ let content = void 0;
173
+ let originalJson = void 0;
174
+ let parseFailed = false;
175
+ try {
176
+ content = await fs$1.readFile(filesPath, "utf8");
177
+ if (content !== void 0) originalJson = JSON.parse(content);
178
+ } catch (e) {
179
+ logger().error(`Error reading or parsing config ${parsedPath.name}:`, e);
180
+ parseFailed = true;
181
+ }
182
+ let json = void 0;
183
+ let migrationFailed = false;
184
+ try {
185
+ if (!parseFailed) json = await migrator.migrate(originalJson, {
186
+ debug: false,
187
+ onStep: async (state, version) => {
188
+ const versionedPath = path.join(parsedPath.dir, `${parsedPath.name}.v${version}.json`);
189
+ try {
190
+ await fs$1.writeFile(versionedPath, JSON.stringify(state));
191
+ logger().info(`Intermediate backup created for ${parsedPath.name} at ${versionedPath}`);
192
+ } catch (e) {
193
+ logger().error(`Failed to create intermediate backup for ${parsedPath.name} at v${version}:`, e);
194
+ }
195
+ }
196
+ });
197
+ else json = migrator.defaultValue;
198
+ } catch (e) {
199
+ logger().error(`Error migrating config ${parsedPath.name}:`, e);
200
+ migrationFailed = true;
201
+ json = migrator.defaultValue;
202
+ }
203
+ if (originalJson?.version !== json?.version || content === void 0 || parseFailed || migrationFailed) {
204
+ if (parseFailed || migrationFailed) try {
205
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
206
+ const corruptedPath = path.join(parsedPath.dir, `${parsedPath.name}.corrupted.${timestamp}.json`);
207
+ const backupContent = parseFailed ? content || "" : JSON.stringify(originalJson, null, 2);
208
+ await fs$1.writeFile(corruptedPath, backupContent);
209
+ logger().info(`Corrupted config file preserved at ${corruptedPath}`);
210
+ } catch (e) {
211
+ logger().error(`Failed to backup corrupted config ${parsedPath.name}:`, e);
212
+ }
213
+ try {
214
+ await fs$1.writeFile(filesPath, JSON.stringify(json));
215
+ } catch (e) {
216
+ logger().error(`Error saving migrated config ${parsedPath.name}:`, e);
217
+ }
218
+ }
219
+ return json;
220
+ }
221
+ };
222
+ };
223
+ const setupSettingsConfigFile = (context) => {
224
+ return setupConfigFile(context.getSettingsPath(), {
225
+ context,
226
+ migrator: appSettingsMigrator
227
+ });
228
+ };
229
+ const setupConnectionsConfigFile = (context) => {
230
+ return setupConfigFile(context.getConnectionsPath(), {
231
+ context,
232
+ migrator: connectionsMigrator
233
+ });
234
+ };
235
+ const setupProjectsConfigFile = (context) => {
236
+ return setupConfigFile(context.getProjectsPath(), {
237
+ context,
238
+ migrator: fileRepoMigrations
239
+ });
240
+ };
241
+ const setupPipelineConfigFileByName = (name, context) => {
242
+ return setupConfigFile(context.getConfigPath(`${name}.json`), {
243
+ context,
244
+ migrator: savedFileMigrator
245
+ });
246
+ };
247
+ const setupPipelineConfigFileByPath = (absolutePath, context) => {
248
+ return setupConfigFile(absolutePath, {
249
+ context,
250
+ migrator: savedFileMigrator
251
+ });
252
+ };
253
+ const deleteConfigFile = async (filesPath) => {
254
+ await fs$1.rm(filesPath, { force: true });
255
+ };
256
+ const deletePipelineConfigFileByName = async (name, context) => {
257
+ await deleteConfigFile(context.getConfigPath(`${name}.json`));
258
+ };
259
+ const deletePipelineConfigFileByPath = async (absolutePath, context) => {
260
+ await deleteConfigFile(absolutePath);
261
+ };
262
+ //#endregion
263
+ export { setupPipelineConfigFileByName as a, setupSettingsConfigFile as c, extractTarGz as d, extractZip as f, zipFolder as h, setupConnectionsConfigFile as i, downloadFile as l, runWithLiveLogs as m, deletePipelineConfigFileByPath as n, setupPipelineConfigFileByPath as o, getFolderSize as p, setupConfigFile as r, setupProjectsConfigFile as s, deletePipelineConfigFileByName as t, ensure as u };
264
+
265
+ //# sourceMappingURL=config-CFgGRD9U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-CFgGRD9U.mjs","names":["mkdirP","fs"],"sources":["../src/utils/fs-extras.ts","../src/config.ts"],"sourcesContent":["import { createWriteStream } from \"node:fs\";\nimport { execa, Options, Subprocess } from \"execa\";\nimport { mkdir as mkdirP, writeFile, stat, readdir } from \"node:fs/promises\";\nimport { join, dirname } from \"node:path\";\nimport tar from \"tar\";\nimport yauzl from \"yauzl\";\nimport archiver from \"archiver\";\nimport { pipeline } from \"node:stream/promises\";\n\n/**\n * Ensures a directory exists and a file is created with default content if missing.\n */\nexport const ensure = async (filesPath: string, defaultContent = \"{}\") => {\n await mkdirP(dirname(filesPath), { recursive: true });\n try {\n const s = await stat(filesPath);\n if (s.size === 0) {\n await writeFile(filesPath, defaultContent);\n }\n } catch {\n await writeFile(filesPath, defaultContent);\n }\n};\n\n/**\n * Extracts a .tar.gz archive.\n */\nexport async function extractTarGz(archivePath: string, destinationDir: string): Promise<void> {\n await mkdirP(destinationDir, { recursive: true });\n await tar.x({\n file: archivePath,\n cwd: destinationDir,\n });\n}\n\n/**\n * Extracts a .zip archive.\n */\nexport async function extractZip(archivePath: string, destinationDir: string): Promise<void> {\n await mkdirP(destinationDir, { recursive: true });\n return new Promise((resolve, reject) => {\n yauzl.open(archivePath, { lazyEntries: true }, (err, zipfile) => {\n if (err || !zipfile) return reject(err || new Error(\"Could not open zip file\"));\n zipfile.on(\"error\", reject);\n zipfile.readEntry();\n zipfile.on(\"entry\", (entry) => {\n const entryPath = join(destinationDir, entry.fileName);\n if (/\\/$/.test(entry.fileName)) {\n mkdirP(entryPath, { recursive: true })\n .then(() => zipfile.readEntry())\n .catch(reject);\n } else {\n mkdirP(dirname(entryPath), { recursive: true })\n .then(() => {\n zipfile.openReadStream(entry, (err, readStream) => {\n if (err || !readStream)\n return reject(err || new Error(\"Could not open read stream\"));\n readStream.on(\"error\", reject);\n const writeStream = createWriteStream(entryPath);\n writeStream.on(\"error\", reject);\n writeStream.on(\"close\", () => zipfile.readEntry());\n readStream.pipe(writeStream);\n });\n })\n .catch(reject);\n }\n });\n zipfile.on(\"end\", () => resolve());\n });\n });\n}\n\n/**\n * Zips a folder.\n */\nexport const zipFolder = async (\n from: string,\n to: string,\n log: typeof console.log = console.log,\n) => {\n const output = createWriteStream(to);\n const archive = archiver(\"zip\", { zlib: { level: 9 } });\n return new Promise<string>((resolve, reject) => {\n output.on(\"close\", () => {\n log(archive.pointer() + \" total bytes\");\n resolve(to);\n });\n archive.on(\"error\", reject);\n archive.pipe(output);\n archive.directory(from, false);\n archive.finalize();\n });\n};\n\n/**\n * Downloads a file with progress tracking.\n */\nexport interface DownloadHooks {\n onProgress?: (data: { progress: number; downloadedSize: number }) => void;\n}\n\nexport const downloadFile = async (\n url: string,\n localPath: string,\n hooks?: DownloadHooks,\n abortSignal?: AbortSignal,\n): Promise<void> => {\n const response = await fetch(url, { signal: abortSignal });\n if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);\n const contentLength = response.headers.get(\"content-length\");\n if (!contentLength) throw new Error(\"Content-Length header is missing\");\n const totalSize = parseInt(contentLength, 10);\n let downloadedSize = 0;\n const fileStream = createWriteStream(localPath);\n const progressStream = new TransformStream({\n transform(chunk, controller) {\n downloadedSize += chunk.length;\n const progress = (downloadedSize / totalSize) * 100;\n hooks?.onProgress?.({ progress, downloadedSize });\n controller.enqueue(chunk);\n },\n });\n const readable = response.body?.pipeThrough(progressStream);\n if (!readable) throw new Error(\"Failed to create a readable stream\");\n await pipeline(readable, fileStream);\n};\n\nexport const runWithLiveLogs = async (\n command: string,\n args: string[],\n execaOptions: Options,\n log: typeof console.log,\n hooks?: {\n onStdout?: (data: string, subprocess: Subprocess) => void;\n onStderr?: (data: string, subprocess: Subprocess) => void;\n onExit?: (code: number) => void;\n onCreated?: (subprocess: Subprocess) => void;\n },\n abortSignal?: AbortSignal,\n): Promise<void> => {\n const subprocess = execa(command, args, {\n ...execaOptions,\n stdout: \"pipe\",\n stderr: \"pipe\",\n stdin: \"pipe\",\n env: {\n ...process.env,\n ...execaOptions.env,\n TERM: \"xterm-256color\",\n FORCE_STDERR_LOGGING: \"1\",\n },\n cancelSignal: abortSignal,\n });\n\n hooks?.onCreated?.(subprocess);\n\n subprocess.stdout?.on(\"data\", (data: Buffer) => {\n hooks?.onStdout?.(data.toString(), subprocess);\n });\n\n subprocess.stderr?.on(\"data\", (data: Buffer) => {\n hooks?.onStderr?.(data.toString(), subprocess);\n });\n\n try {\n const { exitCode } = await subprocess;\n hooks?.onExit?.(exitCode ?? 0);\n } catch (error: any) {\n const code = error.exitCode ?? 1;\n hooks?.onExit?.(code);\n throw new Error(`Command failed with exit code ${code}: ${error.message}`);\n }\n};\n\n/**\n * Calculates the total size of a directory recursively.\n */\nexport async function getFolderSize(dirPath: string): Promise<number> {\n try {\n const files = await readdir(dirPath, { withFileTypes: true });\n const ArrayOfPromises = files.map(async (file) => {\n const path = join(dirPath, file.name);\n if (file.isDirectory()) {\n try {\n return await getFolderSize(path);\n } catch {\n return 0;\n }\n }\n try {\n const { size } = await stat(path);\n return size;\n } catch {\n return 0;\n }\n });\n const results = await Promise.all(ArrayOfPromises);\n return results.reduce((acc, size) => acc + size, 0);\n } catch {\n return 0;\n }\n}\n","import { PipelabContext } from \"./context\";\nimport path from \"node:path\";\nimport { ensure } from \"./utils/fs-extras\";\nimport fs from \"node:fs/promises\";\nimport {\n useLogger,\n Migrator,\n AppConfig,\n ConnectionsConfig,\n FileRepo,\n SavedFile,\n appSettingsMigrator,\n connectionsMigrator,\n fileRepoMigrations,\n savedFileMigrator,\n} from \"@pipelab/shared\";\n\nexport const setupConfigFile = async <T>(\n filesPath: string,\n options: { context: PipelabContext; migrator: Migrator<T> },\n) => {\n const ctx = options.context;\n const parsedPath = path.parse(filesPath);\n const migrator = options.migrator;\n\n await ensure(filesPath, JSON.stringify(migrator.defaultValue));\n\n return {\n setConfig: async (config: T) => {\n const { logger } = useLogger();\n try {\n await fs.writeFile(filesPath, JSON.stringify(config));\n return true;\n } catch (e) {\n logger().error(`Error saving config ${parsedPath.name}:`, e);\n return false;\n }\n },\n getConfig: async () => {\n const { logger } = useLogger();\n let content = undefined;\n let originalJson: any = undefined;\n let parseFailed = false;\n\n try {\n content = await fs.readFile(filesPath, \"utf8\");\n if (content !== undefined) {\n originalJson = JSON.parse(content);\n }\n } catch (e) {\n logger().error(`Error reading or parsing config ${parsedPath.name}:`, e);\n parseFailed = true;\n }\n\n let json: any = undefined;\n let migrationFailed = false;\n try {\n if (!parseFailed) {\n json = await migrator.migrate(originalJson, {\n debug: false,\n onStep: async (state: any, version: string) => {\n const versionedPath = path.join(parsedPath.dir, `${parsedPath.name}.v${version}.json`);\n try {\n await fs.writeFile(versionedPath, JSON.stringify(state));\n logger().info(`Intermediate backup created for ${parsedPath.name} at ${versionedPath}`);\n } catch (e) {\n logger().error(\n `Failed to create intermediate backup for ${parsedPath.name} at v${version}:`,\n e,\n );\n }\n },\n });\n } else {\n json = migrator.defaultValue;\n }\n } catch (e) {\n logger().error(`Error migrating config ${parsedPath.name}:`, e);\n migrationFailed = true;\n json = migrator.defaultValue;\n }\n\n const originalVersion = originalJson?.version;\n const newVersion = json?.version;\n\n const shouldSaveBack =\n originalVersion !== newVersion || content === undefined || parseFailed || migrationFailed;\n\n if (shouldSaveBack) {\n if (parseFailed || migrationFailed) {\n try {\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const corruptedPath = path.join(\n parsedPath.dir,\n `${parsedPath.name}.corrupted.${timestamp}.json`,\n );\n const backupContent = parseFailed\n ? content || \"\"\n : JSON.stringify(originalJson, null, 2);\n await fs.writeFile(corruptedPath, backupContent);\n logger().info(`Corrupted config file preserved at ${corruptedPath}`);\n } catch (e) {\n logger().error(`Failed to backup corrupted config ${parsedPath.name}:`, e);\n }\n }\n\n try {\n await fs.writeFile(filesPath, JSON.stringify(json));\n } catch (e) {\n logger().error(`Error saving migrated config ${parsedPath.name}:`, e);\n }\n }\n\n return json as T;\n },\n };\n};\n\nexport const setupSettingsConfigFile = (context: PipelabContext) => {\n return setupConfigFile<AppConfig>(context.getSettingsPath(), {\n context,\n migrator: appSettingsMigrator,\n });\n};\n\nexport const setupConnectionsConfigFile = (context: PipelabContext) => {\n return setupConfigFile<ConnectionsConfig>(context.getConnectionsPath(), {\n context,\n migrator: connectionsMigrator,\n });\n};\n\nexport const setupProjectsConfigFile = (context: PipelabContext) => {\n return setupConfigFile<FileRepo>(context.getProjectsPath(), {\n context,\n migrator: fileRepoMigrations,\n });\n};\n\nexport const setupPipelineConfigFileByName = (name: string, context: PipelabContext) => {\n const filesPath = context.getConfigPath(`${name}.json`);\n return setupConfigFile<SavedFile>(filesPath, {\n context,\n migrator: savedFileMigrator,\n });\n};\n\nexport const setupPipelineConfigFileByPath = (absolutePath: string, context: PipelabContext) => {\n return setupConfigFile<SavedFile>(absolutePath, {\n context,\n migrator: savedFileMigrator,\n });\n};\n\nconst deleteConfigFile = async (filesPath: string) => {\n await fs.rm(filesPath, { force: true });\n};\n\nexport const deletePipelineConfigFileByName = async (name: string, context: PipelabContext) => {\n const filesPath = context.getConfigPath(`${name}.json`);\n await deleteConfigFile(filesPath);\n};\n\nexport const deletePipelineConfigFileByPath = async (absolutePath: string, context: PipelabContext) => {\n await deleteConfigFile(absolutePath);\n};\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,SAAS,OAAO,WAAmB,iBAAiB,SAAS;AACxE,OAAMA,MAAO,QAAQ,UAAU,EAAE,EAAE,WAAW,MAAM,CAAC;AACrD,KAAI;AAEF,OADU,MAAM,KAAK,UAAU,EACzB,SAAS,EACb,OAAM,UA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UAAU,cAAc,MAAM,EAAE;AACzC,WAAMA,KAAG,UAAU,eAAe,cAAc;AAChD,aAAQ,CAAC,KAAK,sCAAsC,gBAAgB;aAC7D,GAAG;AACV,aAAQ,CAAC,MAAM,qCAAqC,WAAW,KAAK,IAAI,EAAE;;AAI9E,QAAI;AACF,WAAMA,KAAG,UAAU,WAAW,KAAK,UAAU,KAAK,CAAC;aAC5C,GAAG;AACV,aAAQ,CAAC,MAAM,gCAAgC,WAAW,KAAK,IAAI,EAAE;;;AAIzE,UAAO;;EAEV;;AAGH,MAAa,2BAA2B,YAA4B;AAClE,QAAO,gBAA2B,QAAQ,iBAAiB,EAAE;EAC3D;EACA,UAAU;EACX,CAAC;;AAGJ,MAAa,8BAA8B,YAA4B;AACrE,QAAO,gBAAmC,QAAQ,oBAAoB,EAAE;EACtE;EACA,UAAU;EACX,CAAC;;AAGJ,MAAa,2BAA2B,YAA4B;AAClE,QAAO,gBAA0B,QAAQ,iBAAiB,EAAE;EAC1D;EACA,UAAU;EACX,CAAC;;AAGJ,MAAa,iCAAiC,MAAc,YAA4B;AAEtF,QAAO,gBADW,QAAQ,cAAc,GAAG,KAAK,OAAO,EACV;EAC3C;EACA,UAAU;EACX,CAAC;;AAGJ,MAAa,iCAAiC,cAAsB,YAA4B;AAC9F,QAAO,gBAA2B,cAAc;EAC9C;EACA,UAAU;EACX,CAAC;;AAGJ,MAAM,mBAAmB,OAAO,cAAsB;AACpD,OAAMA,KAAG,GAAG,WAAW,EAAE,OAAO,MAAM,CAAC;;AAGzC,MAAa,iCAAiC,OAAO,MAAc,YAA4B;AAE7F,OAAM,iBADY,QAAQ,cAAc,GAAG,KAAK,OAAO,CACtB;;AAGnC,MAAa,iCAAiC,OAAO,cAAsB,YAA4B;AACrG,OAAM,iBAAiB,aAAa"}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { SandboxFolder } from "@pipelab/constants";
3
3
  import { WebSocket } from "ws";
4
- import { Action, Agent, BuildHistoryEntry, Channels, End, Event as Event$1, Events, Expression, ExtractInputsFromAction, ExtractInputsFromEvent, ExtractInputsFromExpression, HandleListenerRendererSendFn, IBuildHistoryStorage, IpcMessage, Migrator, RendererChannels, RendererData, RendererEnd, RendererEvents, RendererMessage, RequestId, SetOutputActionFn, SetOutputExpressionFn, UpdateStatus, Variable, WebSocketConnectionState, WebSocketEvent, WebSocketHandler, WebSocketSendFunction } from "@pipelab/shared";
4
+ import { Action, Agent, BuildHistoryEntry, Channels, End, Event as Event$1, Events, Expression, ExtractInputsFromAction, ExtractInputsFromEvent, ExtractInputsFromExpression, HandleListenerRendererSendFn, IBuildHistoryStorage, IpcMessage, RendererChannels, RendererData, RendererEnd, RendererEvents, RendererMessage, RequestId, SetOutputActionFn, SetOutputExpressionFn, UpdateStatus, Variable, WebSocketConnectionState, WebSocketEvent, WebSocketHandler, WebSocketSendFunction } from "@pipelab/shared";
5
5
  import * as execa$1 from "execa";
6
6
  import { Options as Options$1, Subprocess } from "execa";
7
7
  import * as http$1 from "http";
@@ -11,6 +11,12 @@ import http from "http";
11
11
  declare const isDev: boolean;
12
12
  declare const getDefaultUserDataPath: (env?: "dev" | "beta" | "prod") => string;
13
13
  declare const projectRoot: string | null;
14
+ declare const CacheFolder: {
15
+ readonly Actions: "actions";
16
+ readonly Pipelines: "pipelines";
17
+ readonly Pacote: "pacote";
18
+ };
19
+ type CacheFolderType = (typeof CacheFolder)[keyof typeof CacheFolder];
14
20
  interface PipelabContextOptions {
15
21
  userDataPath: string;
16
22
  releaseTag?: string;
@@ -22,10 +28,18 @@ declare class PipelabContext {
22
28
  getPackagesPath(...subpaths: string[]): string;
23
29
  getThirdPartyPath(...subpaths: string[]): string;
24
30
  getConfigPath(...subpaths: string[]): string;
31
+ getSettingsPath(): string;
32
+ getConnectionsPath(): string;
33
+ getProjectsPath(): string;
34
+ private _cachedSettings;
35
+ private _cachedSettingsTime;
36
+ private getSettings;
25
37
  getTempPath(...subpaths: string[]): string;
26
38
  createTempFolder(prefix?: string): Promise<string>;
27
- getCachePath(...subpaths: string[]): string;
39
+ getCachePath(): string;
40
+ getCachePath(folder: CacheFolderType, ...subpaths: string[]): string;
28
41
  getPnpmPath(...subpaths: string[]): string;
42
+ getBuildHistoryPath(...subpaths: string[]): string;
29
43
  getNodePath(version?: any): string;
30
44
  getPnpmBinPath(version?: any): string;
31
45
  getSandboxFolders(): Array<{
@@ -108,7 +122,6 @@ declare class BuildHistoryStorage implements IBuildHistoryStorage {
108
122
  private ensureStoragePath;
109
123
  private loadPipelineHistory;
110
124
  private savePipelineHistory;
111
- applyRetentionPolicy(): Promise<void>;
112
125
  save(entry: BuildHistoryEntry): Promise<void>;
113
126
  get(id: string, pipelineId?: string): Promise<BuildHistoryEntry | undefined>;
114
127
  getAll(): Promise<BuildHistoryEntry[]>;
@@ -124,11 +137,6 @@ declare class BuildHistoryStorage implements IBuildHistoryStorage {
124
137
  newestEntry?: number;
125
138
  numberOfPipelines: number;
126
139
  userDataPath: string;
127
- retentionPolicy: {
128
- enabled: boolean;
129
- maxEntries: number;
130
- maxAge: number;
131
- };
132
140
  disk: {
133
141
  total: number;
134
142
  free: number;
@@ -141,6 +149,7 @@ declare class BuildHistoryStorage implements IBuildHistoryStorage {
141
149
  };
142
150
  }>;
143
151
  private getAllPipelineFiles;
152
+ private parsePipelineIdFromFilename;
144
153
  }
145
154
  //#endregion
146
155
  //#region src/handlers/index.d.ts
@@ -150,14 +159,28 @@ declare const registerAllHandlers: (options: {
150
159
  }) => Promise<void>;
151
160
  //#endregion
152
161
  //#region src/config.d.ts
153
- declare const getMigrator: <T>(name: string) => Migrator<T>;
154
- declare const setupConfigFile: <T>(name: string, options: {
155
- context: PipelabContext;
156
- migrator?: Migrator<T>;
157
- }) => Promise<{
158
- setConfig: (config: T) => Promise<boolean>;
159
- getConfig: () => Promise<T>;
162
+ declare const setupSettingsConfigFile: (context: PipelabContext) => Promise<{
163
+ setConfig: (config: AppConfig) => Promise<boolean>;
164
+ getConfig: () => Promise<AppConfig>;
165
+ }>;
166
+ declare const setupConnectionsConfigFile: (context: PipelabContext) => Promise<{
167
+ setConfig: (config: ConnectionsConfig) => Promise<boolean>;
168
+ getConfig: () => Promise<ConnectionsConfig>;
169
+ }>;
170
+ declare const setupProjectsConfigFile: (context: PipelabContext) => Promise<{
171
+ setConfig: (config: FileRepo) => Promise<boolean>;
172
+ getConfig: () => Promise<FileRepo>;
160
173
  }>;
174
+ declare const setupPipelineConfigFileByName: (name: string, context: PipelabContext) => Promise<{
175
+ setConfig: (config: SavedFile) => Promise<boolean>;
176
+ getConfig: () => Promise<SavedFile>;
177
+ }>;
178
+ declare const setupPipelineConfigFileByPath: (absolutePath: string, context: PipelabContext) => Promise<{
179
+ setConfig: (config: SavedFile) => Promise<boolean>;
180
+ getConfig: () => Promise<SavedFile>;
181
+ }>;
182
+ declare const deletePipelineConfigFileByName: (name: string, context: PipelabContext) => Promise<void>;
183
+ declare const deletePipelineConfigFileByPath: (absolutePath: string, context: PipelabContext) => Promise<void>;
161
184
  //#endregion
162
185
  //#region src/api.d.ts
163
186
  type HandleListenerRenderer<KEY extends RendererChannels> = (event: Electron.IpcMainInvokeEvent, data: {
@@ -398,14 +421,6 @@ interface RunOptions {
398
421
  }
399
422
  declare function runPipelineCommand(file: string, options: RunOptions, version: string): Promise<any>;
400
423
  //#endregion
401
- //#region src/migrations.d.ts
402
- /**
403
- * Registers migration handlers for the CLI/Standalone server.
404
- * This overrides the default handlers from @pipelab/core-node to include
405
- * pipeline and file repo migrations directly in the backend.
406
- */
407
- declare function registerMigrationHandlers(context: PipelabContext): void;
408
- //#endregion
409
424
  //#region src/server.d.ts
410
425
  interface ServeOptions {
411
426
  port: string | number;
@@ -448,5 +463,5 @@ declare function fetchLatestPackageRelease(packageName: string, options?: FetchR
448
463
  */
449
464
  declare function fetchLatestDesktopRelease(options?: FetchReleaseOptions): Promise<GitHubRelease | null>;
450
465
  //#endregion
451
- export { type Action, ActionRunner, ActionRunnerData, BuildHistoryStorage, ConnectedClient, DownloadHooks, type Event$1 as Event, EventRunner, type Expression, ExpressionRunner, type ExtractInputsFromAction, type ExtractInputsFromEvent, type ExtractInputsFromExpression, FetchOptions, FetchReleaseOptions, GitHubRelease, HandleListener, HandleListenerRenderer, type HandleListenerRendererSendFn, HandleListenerSendFn, ListenerMain, PipelabContext, PipelabContextOptions, type RendererChannels, type RendererData, type RendererEnd, type RendererEvents, type RendererMessage, type RequestId, RunOptions, Runner, RunnerCallbackFnArgument, ServeOptions, type SetOutputActionFn, type SetOutputExpressionFn, type UpdateStatus, UseMainAPI, WebSocketServer, WsEvent, builtInPlugins, downloadFile, ensure, ensureNodeJS, ensurePNPM, executeGraphWithHistory, extractTarGz, extractZip, fetchLatestDesktopRelease, fetchLatestPackageRelease, fetchPackage, fetchPackageReleases, fetchPipelabAsset, fetchPipelabCli, fetchPipelabPlugin, findInstalledPlugins, getDefaultUserDataPath, getFinalPlugins, getFolderSize, getMigrator, handleActionExecute, isDev, isOnline, loadCustomPlugin, loadPipelabPlugin, projectRoot, registerAgentsHandlers, registerAllHandlers, registerConfigHandlers, registerEngineHandlers, registerFsHandlers, registerHistoryHandlers, registerMigrationHandlers, registerShellHandlers, runPipelineCommand, runPnpm, runWithLiveLogs, sendStartupProgress, sendStartupReady, serveCommand, setupConfigFile, useAPI, usePluginAPI, webSocketServer, zipFolder };
466
+ export { type Action, ActionRunner, ActionRunnerData, BuildHistoryStorage, CacheFolder, CacheFolderType, ConnectedClient, DownloadHooks, type Event$1 as Event, EventRunner, type Expression, ExpressionRunner, type ExtractInputsFromAction, type ExtractInputsFromEvent, type ExtractInputsFromExpression, FetchOptions, FetchReleaseOptions, GitHubRelease, HandleListener, HandleListenerRenderer, type HandleListenerRendererSendFn, HandleListenerSendFn, ListenerMain, PipelabContext, PipelabContextOptions, type RendererChannels, type RendererData, type RendererEnd, type RendererEvents, type RendererMessage, type RequestId, RunOptions, Runner, RunnerCallbackFnArgument, ServeOptions, type SetOutputActionFn, type SetOutputExpressionFn, type UpdateStatus, UseMainAPI, WebSocketServer, WsEvent, builtInPlugins, deletePipelineConfigFileByName, deletePipelineConfigFileByPath, downloadFile, ensure, ensureNodeJS, ensurePNPM, executeGraphWithHistory, extractTarGz, extractZip, fetchLatestDesktopRelease, fetchLatestPackageRelease, fetchPackage, fetchPackageReleases, fetchPipelabAsset, fetchPipelabCli, fetchPipelabPlugin, findInstalledPlugins, getDefaultUserDataPath, getFinalPlugins, getFolderSize, handleActionExecute, isDev, isOnline, loadCustomPlugin, loadPipelabPlugin, projectRoot, registerAgentsHandlers, registerAllHandlers, registerConfigHandlers, registerEngineHandlers, registerFsHandlers, registerHistoryHandlers, registerShellHandlers, runPipelineCommand, runPnpm, runWithLiveLogs, sendStartupProgress, sendStartupReady, serveCommand, setupConnectionsConfigFile, setupPipelineConfigFileByName, setupPipelineConfigFileByPath, setupProjectsConfigFile, setupSettingsConfigFile, useAPI, usePluginAPI, webSocketServer, zipFolder };
452
467
  //# sourceMappingURL=index.d.mts.map