verdaccio-stats 0.4.2 → 0.4.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/README.md CHANGED
@@ -28,7 +28,7 @@ Or install to verdaccio plugin folder:
28
28
  mkdir -p ./install-here/
29
29
  npm install --global-style \
30
30
  --bin-links=false --save=false --package-lock=false \
31
- --omit=dev --omit=optional --omit=peer \
31
+ --omit=dev --omit=optional \
32
32
  --prefix ./install-here/ \
33
33
  verdaccio-stats@latest
34
34
  mv ./install-here/node_modules/verdaccio-stats/ /path/to/verdaccio/plugins/
@@ -42,7 +42,7 @@ Add the plugin to your Verdaccio config file:
42
42
  middlewares:
43
43
  stats:
44
44
  enabled: true
45
- dialect: sqlite # Optional: sqlite, mysql, postgres, mariadb, mssql (default: sqlite)
45
+ dialect: sqlite # Optional: sqlite, mysql, postgres, mariadb, mssql, db2, snowflake, oracle (default: sqlite)
46
46
  database: stats.db # For SQLite: path to database file
47
47
  # For other databases, use object configuration:
48
48
  # database:
@@ -73,24 +73,27 @@ For other databases, install the corresponding driver:
73
73
  - MSSQL: `tedious`
74
74
  - SQLite: `sqlite3` (not recommended for production)
75
75
  - Oracle: `oracledb`
76
+ - DB2: `ibm_db`
77
+ - Snowflake: `snowflake-sdk`
76
78
 
77
79
  ### Configuration Options
78
80
 
79
- | Option | Type | Default | Description |
80
- | ---------------------- | ---------------- | ----------------- | ----------------------------------------------------------------- |
81
- | `enabled` | boolean | `true` | Whether the plugin is enabled |
82
- | `dialect` | string | `sqlite` | Database type (`sqlite`, `mysql`, `postgres`, `mariadb`, `mssql`) |
83
- | `database` | string or object | `stats.db` | Database configuration |
84
- | `database.name` | string | `verdaccio_stats` | Database name |
85
- | `database.username` | string | | Database username |
86
- | `database.password` | string | | Database password |
87
- | `database.host` | string | `localhost` | Database host |
88
- | `database.port` | number | `3306` | Database port |
89
- | `iso-week` | boolean | `false` | Whether to use ISO week format |
90
- | `count-downloads` | boolean | `true` | Whether to count downloads |
91
- | `count-manifest-views` | boolean | `true` | Whether to count manifest views |
81
+ | Option | Type | Default | Description |
82
+ | ---------------------- | ---------------- | ----------------- | ------------------------------------------------------------------------------------------------ |
83
+ | `enabled` | boolean | `true` | Whether the plugin is enabled |
84
+ | `dialect` | string | `sqlite` | Database type (`sqlite`, `mysql`, `postgres`, `mariadb`, `mssql`, `db2`, `snowflake`, `oracle`) |
85
+ | `dialect-options` | object | `{}` | Additional options to pass to the database driver |
86
+ | `database` | string or object | `stats.db` | Database configuration |
87
+ | `database.name` | string | `verdaccio_stats` | Database name |
88
+ | `database.username` | string | | Database username |
89
+ | `database.password` | string | | Database password |
90
+ | `database.host` | string | `localhost` | Database host |
91
+ | `database.port` | number | `3306` | Database port |
92
+ | `iso-week` | boolean | `false` | Whether to use ISO week format |
93
+ | `count-downloads` | boolean | `true` | Whether to count downloads |
94
+ | `count-manifest-views` | boolean | `true` | Whether to count manifest views |
92
95
  | `flush-interval` | number or string | `5000` | Flush interval in ms or a duration string (e.g. `5s`, `1m`); `0` = realtime, `<0` disables timer |
93
- | `max-pending-entries` | number | `10000` | Flush when the number of pending entry keys reaches this threshold |
96
+ | `max-pending-entries` | number | `10000` | Flush when the number of pending entry keys reaches this threshold |
94
97
 
95
98
  ## Usage
96
99
 
package/lib/config.d.ts CHANGED
@@ -8,7 +8,11 @@ declare const statsConfig: z.ZodObject<{
8
8
  mysql: "mysql";
9
9
  postgres: "postgres";
10
10
  sqlite: "sqlite";
11
+ db2: "db2";
12
+ snowflake: "snowflake";
13
+ oracle: "oracle";
11
14
  }>>>;
15
+ "dialect-options": z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
12
16
  database: z.ZodUnion<readonly [z.ZodDefault<z.ZodString>, z.ZodObject<{
13
17
  name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
14
18
  username: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -30,6 +34,7 @@ export interface ConfigHolder {
30
34
  isoWeek: boolean;
31
35
  logo?: string;
32
36
  maxPendingEntries: number;
37
+ dialectOptions: Record<string, unknown>;
33
38
  sequelizeOptions: SequelizeOptions;
34
39
  title: string;
35
40
  }
@@ -47,6 +52,7 @@ export declare class ParsedPluginConfig implements ConfigHolder {
47
52
  get maxPendingEntries(): number;
48
53
  get maxPendingKeys(): number;
49
54
  get logo(): string | undefined;
55
+ get dialectOptions(): Record<string, unknown>;
50
56
  get sequelizeOptions(): SequelizeOptions;
51
57
  get title(): string;
52
58
  }
@@ -3,7 +3,7 @@ export declare const plugin: {
3
3
  version: string;
4
4
  };
5
5
  export declare const pluginKey: string;
6
- export declare const DIALECTS: readonly ["mariadb", "mssql", "mysql", "postgres", "sqlite"];
6
+ export declare const DIALECTS: readonly ["mariadb", "mssql", "mysql", "postgres", "sqlite", "db2", "snowflake", "oracle"];
7
7
  export declare const DEFAULT_DIALECT: (typeof DIALECTS)[number];
8
8
  export declare const DEFAULT_SQLITE_STORAGE = "stats.db";
9
9
  export declare const DEFAULT_DATABASE_NAME = "verdaccio_stats";
package/lib/index.js CHANGED
@@ -17,14 +17,14 @@ var sequelize = require('sequelize');
17
17
  var umzug = require('umzug');
18
18
 
19
19
  var name = "verdaccio-stats";
20
- var version = "0.4.2";
20
+ var version = "0.4.3";
21
21
 
22
22
  const plugin = {
23
23
  name,
24
24
  version,
25
25
  };
26
26
  const pluginKey = name.replace("verdaccio-", "");
27
- const DIALECTS = ["mariadb", "mssql", "mysql", "postgres", "sqlite"];
27
+ const DIALECTS = ["mariadb", "mssql", "mysql", "postgres", "sqlite", "db2", "snowflake", "oracle"];
28
28
  const DEFAULT_DIALECT = "sqlite";
29
29
  const DEFAULT_SQLITE_STORAGE = "stats.db";
30
30
  const DEFAULT_DATABASE_NAME = "verdaccio_stats";
@@ -152,6 +152,10 @@ const statsConfig = zod.z
152
152
  .enum(DIALECTS)
153
153
  .optional()
154
154
  .default(() => DEFAULT_DIALECT),
155
+ "dialect-options": zod.z
156
+ .record(zod.z.string(), zod.z.unknown())
157
+ .optional()
158
+ .default(() => ({})),
155
159
  database: zod.z.union([
156
160
  zod.z.string().default(() => DEFAULT_SQLITE_STORAGE),
157
161
  zod.z.object({
@@ -290,26 +294,26 @@ class ParsedPluginConfig {
290
294
  get logo() {
291
295
  return this.verdaccioConfig.web?.logo;
292
296
  }
297
+ get dialectOptions() {
298
+ return this.config["dialect-options"];
299
+ }
293
300
  get sequelizeOptions() {
294
- if (this.config.dialect === "sqlite" && typeof this.config.database === "string") {
301
+ const dialect = this.config.dialect;
302
+ if (dialect === "sqlite") {
295
303
  return {
296
304
  dialect: "sqlite",
297
- storage: normalizeFilePath(this.configPath, this.config.database),
298
- };
299
- }
300
- if (this.config.dialect !== "sqlite" && typeof this.config.database === "object") {
301
- return {
302
- dialect: this.config.dialect,
303
- database: this.config.database.name,
304
- username: this.config.database.username,
305
- password: this.config.database.password,
306
- host: this.config.database.host,
307
- port: this.config.database.port,
305
+ storage: normalizeFilePath(this.configPath, typeof this.config.database === "string" ? this.config.database : DEFAULT_SQLITE_STORAGE),
308
306
  };
309
307
  }
308
+ const dbConfig = (this.config.database ?? {});
309
+ // Non-SQLite dialects
310
310
  return {
311
- dialect: DEFAULT_DIALECT,
312
- storage: normalizeFilePath(this.configPath, DEFAULT_SQLITE_STORAGE),
311
+ dialect: dialect,
312
+ database: dbConfig.name,
313
+ username: dbConfig.username,
314
+ password: dbConfig.password,
315
+ host: dbConfig.host,
316
+ port: dbConfig.port,
313
317
  };
314
318
  }
315
319
  get title() {
@@ -738,9 +742,7 @@ class Database {
738
742
  acquire: 30_000,
739
743
  idle: 10_000,
740
744
  },
741
- dialectOptions: {
742
- timeout: 30_000,
743
- },
745
+ dialectOptions: config.dialectOptions,
744
746
  models: [Package, DownloadStats, ManifestViewStats],
745
747
  });
746
748
  const umzug$1 = new umzug.Umzug({
package/lib/index.mjs CHANGED
@@ -13,14 +13,14 @@ import { Op } from 'sequelize';
13
13
  import { Umzug, SequelizeStorage } from 'umzug';
14
14
 
15
15
  var name = "verdaccio-stats";
16
- var version = "0.4.2";
16
+ var version = "0.4.3";
17
17
 
18
18
  const plugin = {
19
19
  name,
20
20
  version,
21
21
  };
22
22
  const pluginKey = name.replace("verdaccio-", "");
23
- const DIALECTS = ["mariadb", "mssql", "mysql", "postgres", "sqlite"];
23
+ const DIALECTS = ["mariadb", "mssql", "mysql", "postgres", "sqlite", "db2", "snowflake", "oracle"];
24
24
  const DEFAULT_DIALECT = "sqlite";
25
25
  const DEFAULT_SQLITE_STORAGE = "stats.db";
26
26
  const DEFAULT_DATABASE_NAME = "verdaccio_stats";
@@ -148,6 +148,10 @@ const statsConfig = z
148
148
  .enum(DIALECTS)
149
149
  .optional()
150
150
  .default(() => DEFAULT_DIALECT),
151
+ "dialect-options": z
152
+ .record(z.string(), z.unknown())
153
+ .optional()
154
+ .default(() => ({})),
151
155
  database: z.union([
152
156
  z.string().default(() => DEFAULT_SQLITE_STORAGE),
153
157
  z.object({
@@ -286,26 +290,26 @@ class ParsedPluginConfig {
286
290
  get logo() {
287
291
  return this.verdaccioConfig.web?.logo;
288
292
  }
293
+ get dialectOptions() {
294
+ return this.config["dialect-options"];
295
+ }
289
296
  get sequelizeOptions() {
290
- if (this.config.dialect === "sqlite" && typeof this.config.database === "string") {
297
+ const dialect = this.config.dialect;
298
+ if (dialect === "sqlite") {
291
299
  return {
292
300
  dialect: "sqlite",
293
- storage: normalizeFilePath(this.configPath, this.config.database),
294
- };
295
- }
296
- if (this.config.dialect !== "sqlite" && typeof this.config.database === "object") {
297
- return {
298
- dialect: this.config.dialect,
299
- database: this.config.database.name,
300
- username: this.config.database.username,
301
- password: this.config.database.password,
302
- host: this.config.database.host,
303
- port: this.config.database.port,
301
+ storage: normalizeFilePath(this.configPath, typeof this.config.database === "string" ? this.config.database : DEFAULT_SQLITE_STORAGE),
304
302
  };
305
303
  }
304
+ const dbConfig = (this.config.database ?? {});
305
+ // Non-SQLite dialects
306
306
  return {
307
- dialect: DEFAULT_DIALECT,
308
- storage: normalizeFilePath(this.configPath, DEFAULT_SQLITE_STORAGE),
307
+ dialect: dialect,
308
+ database: dbConfig.name,
309
+ username: dbConfig.username,
310
+ password: dbConfig.password,
311
+ host: dbConfig.host,
312
+ port: dbConfig.port,
309
313
  };
310
314
  }
311
315
  get title() {
@@ -734,9 +738,7 @@ class Database {
734
738
  acquire: 30_000,
735
739
  idle: 10_000,
736
740
  },
737
- dialectOptions: {
738
- timeout: 30_000,
739
- },
741
+ dialectOptions: config.dialectOptions,
740
742
  models: [Package, DownloadStats, ManifestViewStats],
741
743
  });
742
744
  const umzug = new Umzug({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verdaccio-stats",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "The stats plugin for Verdaccio",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.mjs",
@@ -66,7 +66,6 @@
66
66
  "dayjs": "^1.11.19",
67
67
  "debug": "^4.4.3",
68
68
  "ms": "^2.1.3",
69
- "reflect-metadata": "^0.2.2",
70
69
  "sequelize": "^6.37.7",
71
70
  "sequelize-typescript": "^2.1.6",
72
71
  "umzug": "^3.8.2",