yamchart 0.4.15 → 0.4.16

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.
@@ -61,7 +61,7 @@ import fastifyStatic from "@fastify/static";
61
61
 
62
62
  // ../server/dist/services/config-loader.js
63
63
  import { readFile, readdir, access } from "fs/promises";
64
- import { join, extname } from "path";
64
+ import { join, extname, relative, dirname } from "path";
65
65
  import { parse as parseYaml } from "yaml";
66
66
  import { watch } from "chokidar";
67
67
  var ConfigLoader = class {
@@ -69,8 +69,12 @@ var ConfigLoader = class {
69
69
  project = null;
70
70
  connections = /* @__PURE__ */ new Map();
71
71
  charts = /* @__PURE__ */ new Map();
72
+ chartFolders = /* @__PURE__ */ new Map();
73
+ chartFilePaths = /* @__PURE__ */ new Map();
72
74
  models = /* @__PURE__ */ new Map();
73
75
  dashboards = /* @__PURE__ */ new Map();
76
+ dashboardFolders = /* @__PURE__ */ new Map();
77
+ dashboardFilePaths = /* @__PURE__ */ new Map();
74
78
  schedules = /* @__PURE__ */ new Map();
75
79
  watcher = null;
76
80
  onChangeCallbacks = [];
@@ -78,6 +82,15 @@ var ConfigLoader = class {
78
82
  this.projectDir = projectDir;
79
83
  }
80
84
  async load() {
85
+ this.connections.clear();
86
+ this.charts.clear();
87
+ this.chartFolders.clear();
88
+ this.chartFilePaths.clear();
89
+ this.models.clear();
90
+ this.dashboards.clear();
91
+ this.dashboardFolders.clear();
92
+ this.dashboardFilePaths.clear();
93
+ this.schedules.clear();
81
94
  await this.loadProject();
82
95
  await this.loadConnections();
83
96
  await this.loadCharts();
@@ -129,18 +142,31 @@ var ConfigLoader = class {
129
142
  } catch {
130
143
  return;
131
144
  }
132
- const files = await readdir(chartsDir);
133
- for (const file of files) {
134
- if (extname(file) !== ".yaml" && extname(file) !== ".yml")
135
- continue;
136
- const filePath = join(chartsDir, file);
137
- const content = await readFile(filePath, "utf-8");
138
- const parsed = parseYaml(content);
139
- const result = ChartSchema.safeParse(parsed);
140
- if (result.success) {
141
- this.charts.set(result.data.name, result.data);
142
- } else {
143
- console.warn(`Invalid chart file ${file}: ${result.error.message}`);
145
+ await this.loadChartsFromDir(chartsDir, chartsDir);
146
+ }
147
+ async loadChartsFromDir(dir, baseDir) {
148
+ const entries = await readdir(dir, { withFileTypes: true });
149
+ for (const entry of entries) {
150
+ const fullPath = join(dir, entry.name);
151
+ if (entry.isDirectory() && dir === baseDir) {
152
+ await this.loadChartsFromDir(fullPath, baseDir);
153
+ } else if (entry.isFile() && (extname(entry.name) === ".yaml" || extname(entry.name) === ".yml")) {
154
+ const content = await readFile(fullPath, "utf-8");
155
+ const parsed = parseYaml(content);
156
+ const result = ChartSchema.safeParse(parsed);
157
+ if (result.success) {
158
+ const name = result.data.name;
159
+ if (this.charts.has(name)) {
160
+ console.warn(`Duplicate chart name "${name}" in ${relative(baseDir, fullPath)} (already loaded from ${relative(baseDir, this.chartFilePaths.get(name))})`);
161
+ continue;
162
+ }
163
+ this.charts.set(name, result.data);
164
+ this.chartFilePaths.set(name, fullPath);
165
+ const relDir = relative(baseDir, dirname(fullPath)).replace(/\\/g, "/");
166
+ this.chartFolders.set(name, relDir || "");
167
+ } else {
168
+ console.warn(`Invalid chart file ${entry.name}: ${result.error.message}`);
169
+ }
144
170
  }
145
171
  }
146
172
  }
@@ -181,18 +207,31 @@ var ConfigLoader = class {
181
207
  } catch {
182
208
  return;
183
209
  }
184
- const files = await readdir(dashboardsDir);
185
- for (const file of files) {
186
- if (extname(file) !== ".yaml" && extname(file) !== ".yml")
187
- continue;
188
- const filePath = join(dashboardsDir, file);
189
- const content = await readFile(filePath, "utf-8");
190
- const parsed = parseYaml(content);
191
- const result = DashboardSchema.safeParse(parsed);
192
- if (result.success) {
193
- this.dashboards.set(result.data.name, result.data);
194
- } else {
195
- console.warn(`Invalid dashboard file ${file}: ${result.error.message}`);
210
+ await this.loadDashboardsFromDir(dashboardsDir, dashboardsDir);
211
+ }
212
+ async loadDashboardsFromDir(dir, baseDir) {
213
+ const entries = await readdir(dir, { withFileTypes: true });
214
+ for (const entry of entries) {
215
+ const fullPath = join(dir, entry.name);
216
+ if (entry.isDirectory() && dir === baseDir) {
217
+ await this.loadDashboardsFromDir(fullPath, baseDir);
218
+ } else if (entry.isFile() && (extname(entry.name) === ".yaml" || extname(entry.name) === ".yml")) {
219
+ const content = await readFile(fullPath, "utf-8");
220
+ const parsed = parseYaml(content);
221
+ const result = DashboardSchema.safeParse(parsed);
222
+ if (result.success) {
223
+ const name = result.data.name;
224
+ if (this.dashboards.has(name)) {
225
+ console.warn(`Duplicate dashboard name "${name}" in ${relative(baseDir, fullPath)} (already loaded from ${relative(baseDir, this.dashboardFilePaths.get(name))})`);
226
+ continue;
227
+ }
228
+ this.dashboards.set(name, result.data);
229
+ this.dashboardFilePaths.set(name, fullPath);
230
+ const relDir = relative(baseDir, dirname(fullPath)).replace(/\\/g, "/");
231
+ this.dashboardFolders.set(name, relDir || "");
232
+ } else {
233
+ console.warn(`Invalid dashboard file ${entry.name}: ${result.error.message}`);
234
+ }
196
235
  }
197
236
  }
198
237
  }
@@ -252,11 +291,6 @@ var ConfigLoader = class {
252
291
  }
253
292
  async reload() {
254
293
  try {
255
- this.connections.clear();
256
- this.charts.clear();
257
- this.models.clear();
258
- this.dashboards.clear();
259
- this.schedules.clear();
260
294
  await this.load();
261
295
  for (const callback of this.onChangeCallbacks) {
262
296
  callback();
@@ -292,6 +326,12 @@ var ConfigLoader = class {
292
326
  getChartByName(name) {
293
327
  return this.charts.get(name);
294
328
  }
329
+ getChartFolder(name) {
330
+ return this.chartFolders.get(name) ?? "";
331
+ }
332
+ getChartFilePath(name) {
333
+ return this.chartFilePaths.get(name);
334
+ }
295
335
  getModels() {
296
336
  return Array.from(this.models.values());
297
337
  }
@@ -315,6 +355,12 @@ var ConfigLoader = class {
315
355
  getDashboardByName(name) {
316
356
  return this.dashboards.get(name);
317
357
  }
358
+ getDashboardFolder(name) {
359
+ return this.dashboardFolders.get(name) ?? "";
360
+ }
361
+ getDashboardFilePath(name) {
362
+ return this.dashboardFilePaths.get(name);
363
+ }
318
364
  getSchedules() {
319
365
  return Array.from(this.schedules.values());
320
366
  }
@@ -646,7 +692,8 @@ async function configRoutes(fastify, options) {
646
692
  name: c.name,
647
693
  title: c.title,
648
694
  description: c.description,
649
- type: c.chart.type
695
+ type: c.chart.type,
696
+ folder: configLoader.getChartFolder(c.name)
650
697
  })),
651
698
  connections: connections.map((c) => ({
652
699
  name: c.name,
@@ -906,7 +953,8 @@ async function dashboardRoutes(fastify, options) {
906
953
  return dashboards.map((d) => ({
907
954
  name: d.name,
908
955
  title: d.title,
909
- description: d.description
956
+ description: d.description,
957
+ folder: configLoader.getDashboardFolder(d.name)
910
958
  }));
911
959
  });
912
960
  fastify.get("/api/dashboards/:id", async (request, reply) => {
@@ -947,7 +995,7 @@ async function dashboardRoutes(fastify, options) {
947
995
  }
948
996
  updated = { ...dashboard, layout };
949
997
  }
950
- const filePath = join3(projectDir, "dashboards", `${id}.yaml`);
998
+ const filePath = configLoader.getDashboardFilePath(id) ?? join3(projectDir, "dashboards", `${id}.yaml`);
951
999
  await writeFile(filePath, stringifyYaml(updated));
952
1000
  await configLoader.load();
953
1001
  const commitMessage = message || `Update ${dashboard.title} layout`;
@@ -13445,10 +13493,10 @@ data: ${data}
13445
13493
  }
13446
13494
 
13447
13495
  // ../server/dist/server.js
13448
- import { join as join4, dirname } from "path";
13496
+ import { join as join4, dirname as dirname2 } from "path";
13449
13497
  import { fileURLToPath } from "url";
13450
13498
  import { access as access2, readFile as readFile2 } from "fs/promises";
13451
- var __dirname = dirname(fileURLToPath(import.meta.url));
13499
+ var __dirname = dirname2(fileURLToPath(import.meta.url));
13452
13500
  var packageJsonPath = join4(__dirname, "..", "package.json");
13453
13501
  var packageJson = JSON.parse(await readFile2(packageJsonPath, "utf-8"));
13454
13502
  var VERSION = packageJson.version;
@@ -13790,4 +13838,4 @@ async function runDevServer(projectDir, options) {
13790
13838
  export {
13791
13839
  runDevServer
13792
13840
  };
13793
- //# sourceMappingURL=dev-7XROGYXG.js.map
13841
+ //# sourceMappingURL=dev-XC47BMBS.js.map