adminforth 1.3.54-next.1 → 1.3.54-next.3

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/basePlugin.ts CHANGED
@@ -16,7 +16,7 @@ export default class AdminForthPlugin implements IAdminForthPlugin {
16
16
  customFolderPath: string;
17
17
  pluginOptions: any;
18
18
  resourceConfig: AdminForthResource;
19
-
19
+ className: string;
20
20
  activationOrder: number = 0;
21
21
 
22
22
  constructor(pluginOptions: any, metaUrl: string) {
@@ -24,6 +24,8 @@ export default class AdminForthPlugin implements IAdminForthPlugin {
24
24
  this.pluginDir = currentFileDir(metaUrl);
25
25
  this.customFolderPath = path.join(this.pluginDir, this.customFolderName);
26
26
  this.pluginOptions = pluginOptions;
27
+ console.log(`🪲 🪲 🪲 🪲 🪲 🪲 AdminForthPlugin.constructor`, this.constructor.name);
28
+ this.className = this.constructor.name;
27
29
  }
28
30
 
29
31
  setupEndpoints(server: any) {
@@ -265,6 +265,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
265
265
  const tableName = resource.table;
266
266
  const where = this.whereClause(resource, filters);
267
267
  const d = this.whereParams(filters);
268
+
268
269
 
269
270
  const countQ = await this.client.query({
270
271
  query: `SELECT COUNT(*) FROM ${tableName} ${where}`,
@@ -272,6 +273,8 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
272
273
  query_params: d,
273
274
  });
274
275
  const countResp = await countQ.json()
276
+ process.env.HEAVY_DEBUG && console.log('🪲🪲⏲️ Clickhouse COUNT', `SELECT COUNT(*) FROM ${tableName} ${where}`, d, 'resp', countResp);
277
+
275
278
  return countResp[0]['COUNT()'];
276
279
  }
277
280
 
@@ -11,6 +11,8 @@ export default class AdminForthPlugin {
11
11
  this.pluginDir = currentFileDir(metaUrl);
12
12
  this.customFolderPath = path.join(this.pluginDir, this.customFolderName);
13
13
  this.pluginOptions = pluginOptions;
14
+ console.log(`🪲 🪲 🪲 🪲 🪲 🪲 AdminForthPlugin.constructor`, this.constructor.name);
15
+ this.className = this.constructor.name;
14
16
  }
15
17
  setupEndpoints(server) {
16
18
  }
@@ -252,6 +252,7 @@ class ClickhouseConnector extends AdminForthBaseConnector {
252
252
  query_params: d,
253
253
  });
254
254
  const countResp = yield countQ.json();
255
+ process.env.HEAVY_DEBUG && console.log('🪲🪲⏲️ Clickhouse COUNT', `SELECT COUNT(*) FROM ${tableName} ${where}`, d, 'resp', countResp);
255
256
  return countResp[0]['COUNT()'];
256
257
  });
257
258
  }
package/dist/index.js CHANGED
@@ -72,6 +72,21 @@ class AdminForth {
72
72
  this.activatedPlugins.push(pluginInstance);
73
73
  });
74
74
  }
75
+ getPluginsByClassName(className) {
76
+ const plugins = this.activatedPlugins.filter((plugin) => plugin.className === className);
77
+ return plugins;
78
+ }
79
+ getPluginByClassName(className) {
80
+ const plugins = this.getPluginsByClassName(className);
81
+ if (plugins.length > 1) {
82
+ throw new Error(`Multiple plugins with className ${className} found. Use getPluginsByClassName instead`);
83
+ }
84
+ if (plugins.length === 0) {
85
+ const similar = suggestIfTypo(this.activatedPlugins.map((p) => p.className), className);
86
+ throw new Error(`Plugin with className ${className} not found. ${similar ? `Did you mean ${similar}?` : ''}`);
87
+ }
88
+ return plugins[0];
89
+ }
75
90
  discoverDatabases() {
76
91
  return __awaiter(this, void 0, void 0, function* () {
77
92
  this.statuses.dbDiscover = 'running';
package/index.ts CHANGED
@@ -126,6 +126,23 @@ class AdminForth implements IAdminForth {
126
126
  );
127
127
  }
128
128
 
129
+ getPluginsByClassName<T>(className: string): T[] {
130
+ const plugins = this.activatedPlugins.filter((plugin) => plugin.className === className);
131
+ return plugins as T[];
132
+ }
133
+
134
+ getPluginByClassName<T>(className: string): T {
135
+ const plugins = this.getPluginsByClassName(className);
136
+ if (plugins.length > 1) {
137
+ throw new Error(`Multiple plugins with className ${className} found. Use getPluginsByClassName instead`);
138
+ }
139
+ if (plugins.length === 0) {
140
+ const similar = suggestIfTypo(this.activatedPlugins.map((p) => p.className), className);
141
+ throw new Error(`Plugin with className ${className} not found. ${similar ? `Did you mean ${similar}?` : ''}`);
142
+ }
143
+ return plugins[0] as T;
144
+ }
145
+
129
146
  async discoverDatabases() {
130
147
  this.statuses.dbDiscover = 'running';
131
148
  this.connectorClasses = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.3.54-next.1",
3
+ "version": "1.3.54-next.3",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -325,6 +325,7 @@ export interface IAdminForthPlugin {
325
325
  customFolderPath: string;
326
326
  pluginOptions: any;
327
327
  resourceConfig: AdminForthResource;
328
+ className: string;
328
329
 
329
330
  /**
330
331
  * Before activating all plugins are sorted by this number and then activated in order.