verdaccio-stats 0.1.0
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/LICENSE +21 -0
- package/README.md +67 -0
- package/lib/config.d.ts +40 -0
- package/lib/constants.d.ts +11 -0
- package/lib/debugger.d.ts +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +683 -0
- package/lib/index.mjs +679 -0
- package/lib/logger.d.ts +4 -0
- package/lib/middlewares/admin-ui.d.ts +17 -0
- package/lib/middlewares/hooks.d.ts +13 -0
- package/lib/middlewares/stats.d.ts +16 -0
- package/lib/migrations.d.ts +3 -0
- package/lib/models.d.ts +23 -0
- package/lib/plugin.d.ts +12 -0
- package/lib/storage/db.d.ts +19 -0
- package/lib/types.d.ts +7 -0
- package/lib/utils.d.ts +33 -0
- package/package.json +76 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Application, Handler } from "express";
|
|
2
|
+
import type { ConfigHolder } from "../config";
|
|
3
|
+
import type { PluginMiddleware } from "../types";
|
|
4
|
+
import { Database } from "../storage/db";
|
|
5
|
+
export declare class Hooks implements PluginMiddleware {
|
|
6
|
+
private config;
|
|
7
|
+
private db;
|
|
8
|
+
constructor(config: ConfigHolder);
|
|
9
|
+
packageManifestHandler: Handler;
|
|
10
|
+
register_middlewares(app: Application): void;
|
|
11
|
+
setDatabase(db: Database): void;
|
|
12
|
+
tarballDownloadHandler: Handler;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Application } from "express";
|
|
2
|
+
import type { ConfigHolder } from "../config";
|
|
3
|
+
import type { PluginMiddleware } from "../types";
|
|
4
|
+
import { Database } from "../storage/db";
|
|
5
|
+
/**
|
|
6
|
+
* NOTE: This middleware is not implemented yet.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Stats implements PluginMiddleware {
|
|
9
|
+
private config;
|
|
10
|
+
private db;
|
|
11
|
+
constructor(config: ConfigHolder);
|
|
12
|
+
register_middlewares(app: Application): void;
|
|
13
|
+
setDatabase(db: Database): void;
|
|
14
|
+
private checkDatabase;
|
|
15
|
+
private notImplementedHandler;
|
|
16
|
+
}
|
package/lib/models.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CreationOptional, ForeignKey, type InferAttributes, type InferCreationAttributes, Model, NonAttribute } from "sequelize";
|
|
2
|
+
import type { PeriodType, PeriodValue } from "./types";
|
|
3
|
+
export declare class DownloadStats extends Model<InferAttributes<DownloadStats>, InferCreationAttributes<DownloadStats>> {
|
|
4
|
+
count: number;
|
|
5
|
+
id: CreationOptional<number>;
|
|
6
|
+
package?: NonAttribute<Package>;
|
|
7
|
+
packageId: ForeignKey<Package["id"]>;
|
|
8
|
+
periodType: PeriodType;
|
|
9
|
+
periodValue: PeriodValue;
|
|
10
|
+
}
|
|
11
|
+
export declare class ManifestViewStats extends Model<InferAttributes<ManifestViewStats>, InferCreationAttributes<ManifestViewStats>> {
|
|
12
|
+
count: number;
|
|
13
|
+
id: CreationOptional<number>;
|
|
14
|
+
package?: NonAttribute<Package>;
|
|
15
|
+
packageId: ForeignKey<Package["id"]>;
|
|
16
|
+
periodType: PeriodType;
|
|
17
|
+
periodValue: PeriodValue;
|
|
18
|
+
}
|
|
19
|
+
export declare class Package extends Model<InferAttributes<Package>, InferCreationAttributes<Package>> {
|
|
20
|
+
id: CreationOptional<number>;
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
}
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { pluginUtils } from "@verdaccio/core";
|
|
2
|
+
import type { Express } from "express";
|
|
3
|
+
import { type StatsConfig } from "./config";
|
|
4
|
+
export declare class Plugin implements pluginUtils.ExpressMiddleware<StatsConfig, never, never> {
|
|
5
|
+
config: StatsConfig;
|
|
6
|
+
options: pluginUtils.PluginOptions;
|
|
7
|
+
get version(): number;
|
|
8
|
+
private parsedConfig;
|
|
9
|
+
constructor(config: StatsConfig, options: pluginUtils.PluginOptions);
|
|
10
|
+
getVersion(): number;
|
|
11
|
+
register_middlewares(app: Express): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConfigHolder } from "../config";
|
|
2
|
+
export declare class Database {
|
|
3
|
+
private config;
|
|
4
|
+
private sequelize;
|
|
5
|
+
private umzug;
|
|
6
|
+
private constructor();
|
|
7
|
+
static create(config: ConfigHolder): Promise<Database>;
|
|
8
|
+
addDownloadCount(packageName: string, version: string): Promise<void>;
|
|
9
|
+
addManifestViewCount(packageName: string, version?: string): Promise<void>;
|
|
10
|
+
migrate(): Promise<import("umzug").MigrationMeta[]>;
|
|
11
|
+
rollback(): Promise<import("umzug").MigrationMeta[]>;
|
|
12
|
+
private addDownloadForAllPeriod;
|
|
13
|
+
private addManifestViewForAllPeriod;
|
|
14
|
+
private addPackageDownloadCount;
|
|
15
|
+
private addPackageManifestViewCount;
|
|
16
|
+
private addTotalDownloadCount;
|
|
17
|
+
private addTotalManifestViewCount;
|
|
18
|
+
private init;
|
|
19
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Application } from "express";
|
|
2
|
+
import type { PERIOD_TYPES, PERIOD_VALUE_TOTAL } from "./constants";
|
|
3
|
+
export type PeriodType = (typeof PERIOD_TYPES)[number];
|
|
4
|
+
export type PeriodValue = (Record<never, never> & string) | typeof PERIOD_VALUE_TOTAL;
|
|
5
|
+
export interface PluginMiddleware {
|
|
6
|
+
register_middlewares(app: Application): void;
|
|
7
|
+
}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Dayjs } from "dayjs";
|
|
2
|
+
import type { PeriodType, PeriodValue } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Get the period value for the given period type.
|
|
5
|
+
*
|
|
6
|
+
* @param periodType {PeriodType} - The period type.
|
|
7
|
+
* @param date {Dayjs} - The date to get the period value for.
|
|
8
|
+
* @param isoWeek {boolean} - Whether to use ISO week format.
|
|
9
|
+
* @returns {PeriodValue} The period value.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPeriodValue(periodType: PeriodType, date?: Dayjs, isoWeek?: boolean): PeriodValue;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the status code is a success status code.
|
|
14
|
+
*
|
|
15
|
+
* @param statusCode {number} - The status code.
|
|
16
|
+
* @returns {boolean} Whether the status code is a success status code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isSuccessStatus(statusCode: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the absolute path of a file path.
|
|
21
|
+
*
|
|
22
|
+
* @param configPath {string} - The path to the config file.
|
|
23
|
+
* @param targetPath {string} - The path to the files.
|
|
24
|
+
* @returns {string} The absolute path of the file.
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizeFilePath(configPath: string, targetPath: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Wraps the given URL path for Verdaccio stats.
|
|
29
|
+
*
|
|
30
|
+
* @param urlPath {string} - The path to be wrapped.
|
|
31
|
+
* @returns {string} The wrapped path.
|
|
32
|
+
*/
|
|
33
|
+
export declare function wrapPath(urlPath: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "verdaccio-stats",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The stats plugin for Verdaccio",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.mjs",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"repository": "https://github.com/kuoruan/verdaccio-stats.git",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"verdaccio",
|
|
11
|
+
"plugin",
|
|
12
|
+
"stats"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
"lib"
|
|
16
|
+
],
|
|
17
|
+
"author": "Xingwang Liao<kuoruan@gmail.com>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@eslint/js": "^9.21.0",
|
|
21
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
22
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
23
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
24
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
25
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
26
|
+
"@types/debug": "^4.1.12",
|
|
27
|
+
"@types/express": "^5.0.0",
|
|
28
|
+
"@verdaccio/types": "13.0.0-next-8.3",
|
|
29
|
+
"cross-env": "^7.0.3",
|
|
30
|
+
"eslint": "^9.21.0",
|
|
31
|
+
"eslint-config-prettier": "^10.0.2",
|
|
32
|
+
"eslint-import-resolver-next": "^0.4.2",
|
|
33
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
34
|
+
"eslint-plugin-perfectionist": "^4.9.0",
|
|
35
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
36
|
+
"eslint-plugin-unicorn": "^57.0.0",
|
|
37
|
+
"express": "^4.21.2",
|
|
38
|
+
"globals": "^16.0.0",
|
|
39
|
+
"prettier": "^3.5.3",
|
|
40
|
+
"rimraf": "^6.0.1",
|
|
41
|
+
"rollup": "^4.34.9",
|
|
42
|
+
"rollup-plugin-node-externals": "^8.0.0",
|
|
43
|
+
"tslib": "^2.8.1",
|
|
44
|
+
"typescript": "^5.8.2",
|
|
45
|
+
"typescript-eslint": "^8.26.0",
|
|
46
|
+
"verdaccio": "^6.0.5",
|
|
47
|
+
"verdaccio-stats": "file:",
|
|
48
|
+
"vitest": "^3.0.8"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"verdaccio": "^5.0.0||^6.0.0"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@adminjs/express": "^6.1.1",
|
|
58
|
+
"@adminjs/sequelize": "^4.1.1",
|
|
59
|
+
"@verdaccio/core": "8.0.0-next-8.10",
|
|
60
|
+
"@verdaccio/middleware": "8.0.0-next-8.10",
|
|
61
|
+
"adminjs": "^7.8.15",
|
|
62
|
+
"dayjs": "^1.11.13",
|
|
63
|
+
"debug": "^4.4.0",
|
|
64
|
+
"sequelize": "^6.37.6",
|
|
65
|
+
"sqlite3": "^5.1.7",
|
|
66
|
+
"umzug": "^3.8.2",
|
|
67
|
+
"zod": "^3.24.2"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"start": "cross-env DEBUG='verdaccio:*' node_modules/verdaccio/bin/verdaccio -c verdaccio/verdaccio.yml",
|
|
71
|
+
"build": "rimraf dist && rollup -c --environment NODE_ENV:production",
|
|
72
|
+
"lint": "eslint .",
|
|
73
|
+
"lint:fix": "eslint --fix .",
|
|
74
|
+
"test": "vitest --run"
|
|
75
|
+
}
|
|
76
|
+
}
|