@rsdoctor/types 1.5.8 → 1.5.10

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.
Files changed (64) hide show
  1. package/dist/babel.d.cts +13 -0
  2. package/dist/client.d.cts +164 -0
  3. package/dist/common.d.cts +26 -0
  4. package/dist/config.d.cts +75 -0
  5. package/dist/constants.d.cts +19 -0
  6. package/dist/emo.d.cts +28 -0
  7. package/dist/error.d.cts +137 -0
  8. package/dist/esbuild.d.cts +30 -0
  9. package/dist/index.d.cts +15 -0
  10. package/dist/linter/diagnostic.d.cts +48 -0
  11. package/dist/linter/index.d.cts +2 -0
  12. package/dist/linter/rule.d.cts +105 -0
  13. package/dist/logger.d.cts +9 -0
  14. package/dist/manifest.d.cts +68 -0
  15. package/dist/modules.d.cts +7 -0
  16. package/dist/plugin/baseCompiler.d.cts +33 -0
  17. package/dist/plugin/baseLoader.d.cts +78 -0
  18. package/dist/plugin/baseStats.d.cts +139 -0
  19. package/dist/plugin/index.d.cts +7 -0
  20. package/dist/plugin/internal-rules.d.cts +4 -0
  21. package/dist/plugin/plugin.d.cts +159 -0
  22. package/dist/plugin/rspack.d.cts +37 -0
  23. package/dist/plugin/webpack.d.cts +13 -0
  24. package/dist/rule/code/E1001.d.cts +3 -0
  25. package/dist/rule/code/E1002.d.cts +3 -0
  26. package/dist/rule/code/E1003.d.cts +3 -0
  27. package/dist/rule/code/E1004.d.cts +3 -0
  28. package/dist/rule/code/E1005.d.cts +3 -0
  29. package/dist/rule/code/E1006.d.cts +3 -0
  30. package/dist/rule/code/E1007.d.cts +3 -0
  31. package/dist/rule/code/E1008.d.cts +3 -0
  32. package/dist/rule/code/E1009.d.cts +3 -0
  33. package/dist/rule/code/index.d.cts +33 -0
  34. package/dist/rule/code/type.d.cts +27 -0
  35. package/dist/rule/data.d.cts +217 -0
  36. package/dist/rule/index.d.cts +2 -0
  37. package/dist/sdk/chunk.d.cts +142 -0
  38. package/dist/sdk/config.d.cts +12 -0
  39. package/dist/sdk/context.d.cts +23 -0
  40. package/dist/sdk/envinfo.d.cts +19 -0
  41. package/dist/sdk/hooks.d.cts +14 -0
  42. package/dist/sdk/index.d.cts +16 -0
  43. package/dist/sdk/instance.d.cts +110 -0
  44. package/dist/sdk/loader.d.cts +70 -0
  45. package/dist/sdk/module.d.cts +405 -0
  46. package/dist/sdk/package.d.cts +124 -0
  47. package/dist/sdk/plugin.d.cts +21 -0
  48. package/dist/sdk/process.d.cts +10 -0
  49. package/dist/sdk/resolver.d.cts +52 -0
  50. package/dist/sdk/result.d.cts +42 -0
  51. package/dist/sdk/server/apis/alerts.d.cts +30 -0
  52. package/dist/sdk/server/apis/graph.d.cts +49 -0
  53. package/dist/sdk/server/apis/index.d.cts +189 -0
  54. package/dist/sdk/server/apis/loader.d.cts +53 -0
  55. package/dist/sdk/server/apis/pagination.d.cts +11 -0
  56. package/dist/sdk/server/apis/plugin.d.cts +19 -0
  57. package/dist/sdk/server/apis/project.d.cts +18 -0
  58. package/dist/sdk/server/apis/resolver.d.cts +18 -0
  59. package/dist/sdk/server/index.d.cts +24 -0
  60. package/dist/sdk/statement.d.cts +178 -0
  61. package/dist/sdk/summary.d.cts +18 -0
  62. package/dist/sdk/treeShaking.d.cts +152 -0
  63. package/dist/thirdparty.d.cts +2 -0
  64. package/package.json +10 -5
@@ -0,0 +1,13 @@
1
+ /** Babel Error */
2
+ export interface Error {
3
+ code: string;
4
+ reasonCode: string;
5
+ message: string;
6
+ name: string;
7
+ stack: string;
8
+ pos?: number;
9
+ loc?: {
10
+ line: number;
11
+ column: number;
12
+ };
13
+ }
@@ -0,0 +1,164 @@
1
+ import type { ModuleSize } from './sdk/module';
2
+ export declare enum RsdoctorClientUrlQuery {
3
+ BundleDiffFiles = "__bundle_files__",
4
+ ManifestFile = "manifest",
5
+ EnableRoutes = "enableRoutes"
6
+ }
7
+ export declare enum RsdoctorClientRoutes {
8
+ Home = "/",
9
+ Overall = "/overall",
10
+ WebpackLoaderOverall = "/webpack/loaders/overall",
11
+ WebpackLoaderAnalysis = "/webpack/loaders/analysis",
12
+ ModuleResolve = "/module/resolve",
13
+ WebpackPlugins = "/webpack/plugins",
14
+ BundleSize = "/bundle/size",
15
+ ModuleAnalyze = "/module/analyze",
16
+ TreeShaking = "/treeshaking",
17
+ BundleDiff = "/resources/bundle/diff",
18
+ RuleIndex = "/resources/rules",
19
+ Uploader = "/resources/uploader",
20
+ EmoCheck = "/emo/check"
21
+ }
22
+ export declare enum RsdoctorClientDiffState {
23
+ Equal = "-",
24
+ Up = "UP",
25
+ Down = "DOWN"
26
+ }
27
+ export interface RsdoctorClientAssetsDiffItem {
28
+ size: {
29
+ baseline: number;
30
+ current: number;
31
+ };
32
+ count: {
33
+ baseline: number;
34
+ current: number;
35
+ };
36
+ percent: number;
37
+ state: RsdoctorClientDiffState;
38
+ }
39
+ export interface RsdoctorClientAssetsDiffResult {
40
+ all: {
41
+ total: RsdoctorClientAssetsDiffItem;
42
+ };
43
+ js: {
44
+ total: RsdoctorClientAssetsDiffItem;
45
+ initial: RsdoctorClientAssetsDiffItem;
46
+ };
47
+ css: {
48
+ total: RsdoctorClientAssetsDiffItem;
49
+ initial: RsdoctorClientAssetsDiffItem;
50
+ };
51
+ imgs: {
52
+ total: RsdoctorClientAssetsDiffItem;
53
+ };
54
+ html: {
55
+ total: RsdoctorClientAssetsDiffItem;
56
+ };
57
+ media: {
58
+ total: RsdoctorClientAssetsDiffItem;
59
+ };
60
+ fonts: {
61
+ total: RsdoctorClientAssetsDiffItem;
62
+ };
63
+ /**
64
+ * files exclude these extensions above
65
+ */
66
+ others: {
67
+ total: RsdoctorClientAssetsDiffItem;
68
+ };
69
+ }
70
+ interface AssetInfo {
71
+ size: number;
72
+ count: number;
73
+ files: {
74
+ path: string;
75
+ size: number;
76
+ initial: boolean;
77
+ content: string | void;
78
+ }[];
79
+ }
80
+ export interface RsdoctorClientAssetsSummary {
81
+ all: {
82
+ total: AssetInfo;
83
+ };
84
+ js: {
85
+ total: AssetInfo;
86
+ initial: AssetInfo;
87
+ };
88
+ css: {
89
+ total: AssetInfo;
90
+ initial: AssetInfo;
91
+ };
92
+ imgs: {
93
+ total: AssetInfo;
94
+ };
95
+ html: {
96
+ total: AssetInfo;
97
+ };
98
+ media: {
99
+ total: AssetInfo;
100
+ };
101
+ fonts: {
102
+ total: AssetInfo;
103
+ };
104
+ /**
105
+ * files exclude these extensions above
106
+ */
107
+ others: {
108
+ total: AssetInfo;
109
+ };
110
+ }
111
+ export interface RsdoctorClientModuleDiffItem {
112
+ path: string;
113
+ size: {
114
+ baseline: ModuleSize;
115
+ current: ModuleSize;
116
+ };
117
+ /** Percent change based on parsedSize */
118
+ percent: number;
119
+ state: RsdoctorClientDiffState;
120
+ }
121
+ export interface RsdoctorClientModulesDiffResult {
122
+ added: Array<{
123
+ path: string;
124
+ size: ModuleSize;
125
+ }>;
126
+ removed: Array<{
127
+ path: string;
128
+ size: ModuleSize;
129
+ }>;
130
+ changed: RsdoctorClientModuleDiffItem[];
131
+ }
132
+ export interface RsdoctorClientPackageDiffItem {
133
+ name: string;
134
+ version: string;
135
+ root: string;
136
+ size: {
137
+ baseline: ModuleSize;
138
+ current: ModuleSize;
139
+ };
140
+ /** Percent change based on parsedSize */
141
+ percent: number;
142
+ state: RsdoctorClientDiffState;
143
+ }
144
+ export interface RsdoctorClientPackagesDiffResult {
145
+ added: Array<{
146
+ name: string;
147
+ version: string;
148
+ root: string;
149
+ size: ModuleSize;
150
+ }>;
151
+ removed: Array<{
152
+ name: string;
153
+ version: string;
154
+ root: string;
155
+ size: ModuleSize;
156
+ }>;
157
+ changed: RsdoctorClientPackageDiffItem[];
158
+ }
159
+ export interface RsdoctorClientBundleDiffResult {
160
+ assets: RsdoctorClientAssetsDiffResult;
161
+ modules: RsdoctorClientModulesDiffResult;
162
+ packages: RsdoctorClientPackagesDiffResult;
163
+ }
164
+ export {};
@@ -0,0 +1,26 @@
1
+ export type NonFunctionPropertyNames<T> = {
2
+ [K in keyof T]: T[K] extends Function ? never : K;
3
+ }[keyof T];
4
+ export type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
5
+ export type PlainObject<T = any> = {
6
+ [key: string]: T;
7
+ };
8
+ export type PromiseReturnType<T> = T extends (...args: any[]) => Promise<infer P> ? P : T;
9
+ export type DeepRequired<T> = T extends PlainObject ? {
10
+ [K in keyof T]-?: DeepRequired<T[K]>;
11
+ } : T;
12
+ export type OrPromise<T> = T | Promise<T>;
13
+ export type Constructor<T> = T extends abstract new (...args: infer P1) => infer R1 ? new (...args: P1) => R1 : T extends new (...args: infer P2) => infer R2 ? new (...args: P2) => R2 : never;
14
+ export type Function<P extends any[] = any[], R = any> = (...args: P) => R;
15
+ export type FunctionPropertyNames<T> = {
16
+ [K in keyof T]: T[K] extends Function ? K : never;
17
+ }[keyof T];
18
+ export type Get<T, K, F = never> = K extends keyof T ? T[K] : F;
19
+ export type ObjectPropertyNames<T> = {
20
+ [K in keyof T]: T[K] extends PlainObject ? K : never;
21
+ }[keyof T];
22
+ export type ArrayToUnion<T extends any[]> = T[number];
23
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
24
+ export type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
25
+ export type Push<T extends any[], V> = [...T, V];
26
+ export type UnionToTuple<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple<Exclude<T, L>>, L>;
@@ -0,0 +1,75 @@
1
+ export interface BriefConfig {
2
+ reportHtmlName?: string;
3
+ writeDataJson: boolean;
4
+ }
5
+ /**
6
+ * @deprecated This type is deprecated and will be removed in a future version.
7
+ * Use {@link NewReportCodeType} instead for better type safety and consistency.
8
+ */
9
+ export type IReportCodeType = {
10
+ noModuleSource?: boolean;
11
+ noAssetsAndModuleSource?: boolean;
12
+ noCode?: boolean;
13
+ };
14
+ export interface NormalModeOptions {
15
+ type?: never;
16
+ }
17
+ interface JsonSectionOptions {
18
+ /**
19
+ * @default: true
20
+ * */
21
+ moduleGraph?: boolean;
22
+ /**
23
+ * @default: true
24
+ * */
25
+ chunkGraph?: boolean;
26
+ /**
27
+ * @default: true
28
+ * */
29
+ rules?: boolean;
30
+ }
31
+ export interface JsonOptions {
32
+ fileName?: string;
33
+ sections?: JsonSectionOptions;
34
+ }
35
+ export interface BriefModeOptions {
36
+ /** Output type, supports HTML and JSON */
37
+ type?: Array<'html' | 'json'>;
38
+ /** HTML output related configuration */
39
+ htmlOptions?: BriefConfig;
40
+ /** JSON output related configuration */
41
+ jsonOptions?: JsonOptions;
42
+ }
43
+ interface OutputBaseConfig {
44
+ /**
45
+ * The directory where the report files will be output.
46
+ */
47
+ reportDir?: string;
48
+ /**
49
+ * Control the Rsdoctor reporter codes records.
50
+ */
51
+ reportCodeType?: IReportCodeType | undefined | NewReportCodeType;
52
+ /**
53
+ * @deprecated
54
+ * Configure whether to compress data.
55
+ * @default false
56
+ *
57
+ */
58
+ compressData?: boolean;
59
+ }
60
+ export interface BriefModeConfig extends Omit<OutputBaseConfig, 'reportCodeType' | 'mode'> {
61
+ mode?: 'brief';
62
+ reportCodeType?: ReportCodeTypeByMode<'brief'>;
63
+ options?: BriefModeOptions;
64
+ }
65
+ interface NormalModeConfig extends Omit<OutputBaseConfig, 'reportCodeType' | 'mode'> {
66
+ mode?: 'normal';
67
+ reportCodeType?: ReportCodeTypeByMode<'normal'>;
68
+ options?: NormalModeOptions;
69
+ }
70
+ type ReportCodeTypeByMode<T extends 'brief' | 'normal'> = T extends 'brief' ? undefined | 'noCode' | {
71
+ noCode?: boolean;
72
+ } : T extends 'normal' ? IReportCodeType | undefined | NewReportCodeType : IReportCodeType | undefined | NewReportCodeType;
73
+ export type IOutput<T extends 'brief' | 'normal'> = T extends 'brief' ? BriefModeConfig : T extends 'normal' ? NormalModeConfig : BriefModeConfig | NormalModeConfig | OutputBaseConfig;
74
+ export type NewReportCodeType = 'noModuleSource' | 'noAssetsAndModuleSource' | 'noCode';
75
+ export {};
@@ -0,0 +1,19 @@
1
+ export declare const JSExtension = ".js";
2
+ export declare const BundleExtension = ".bundle";
3
+ export declare const JSExtensions: string[];
4
+ export declare const CSSExtension = ".css";
5
+ export declare const HtmlExtension = ".html";
6
+ export declare const ImgExtensions: string[];
7
+ export declare const MediaExtensions: string[];
8
+ export declare const FontExtensions: string[];
9
+ export declare const MapExtensions: string[];
10
+ export declare const RsdoctorOutputFolder = ".rsdoctor";
11
+ export declare const RsdoctorOutputManifest = "manifest.json";
12
+ export declare const RsdoctorOutputManifestPath: ".rsdoctor/manifest.json";
13
+ export declare const StatsFilePath = "dist/stats.json";
14
+ export declare const RsdoctorMonitorNodeBId = "Rsdoctor";
15
+ export declare const RsdoctorMonitorWebBId = "Rsdoctor-Client";
16
+ export declare const RsdoctorMonitorDocBId = "Rsdoctor-Doc";
17
+ export declare const RsdoctorProcessEnvDebugKey = "rsdoctor";
18
+ export declare const RsdoctorClientUrl = "";
19
+ export declare const WINDOW_RSDOCTOR_TAG = "__RSDOCTOR__";
package/dist/emo.d.cts ADDED
@@ -0,0 +1,28 @@
1
+ export type WorkspaceCheckDataType = {
2
+ message: string;
3
+ type: 'issues' | 'message' | 'code';
4
+ title: string;
5
+ severity?: EmoCheckSeverity;
6
+ result?: {
7
+ package: string;
8
+ data: Record<string, string | string[]>[];
9
+ tag?: string;
10
+ } | {
11
+ path: string;
12
+ line?: number;
13
+ column?: number;
14
+ }[] | Record<string, {
15
+ version: string;
16
+ pkgname: string;
17
+ }>;
18
+ issues?: string[];
19
+ };
20
+ export type EmoCheckData = {
21
+ projectInfo: Record<string, string | Object>;
22
+ workspaceRes: Record<string, WorkspaceCheckDataType[]>;
23
+ };
24
+ export declare enum EmoCheckSeverity {
25
+ Error = 0,
26
+ Warn = 1,
27
+ Info = 2
28
+ }
@@ -0,0 +1,137 @@
1
+ import type { NonFunctionProperties } from './common';
2
+ import type { BaseRuleStoreData } from './rule';
3
+ /**
4
+ * Position
5
+ * - `line` start with `1`
6
+ * - `column` start with `0`
7
+ */
8
+ export interface Position {
9
+ line: number;
10
+ column: number;
11
+ }
12
+ /** Range of Position */
13
+ export interface Range {
14
+ start: Position;
15
+ end: Position;
16
+ }
17
+ /** Offset range */
18
+ export interface OffsetRange {
19
+ start: number;
20
+ end: number;
21
+ }
22
+ /** Error Level */
23
+ export declare enum ErrorLevel {
24
+ Ignore = 0,
25
+ Warn = 1,
26
+ Error = 2
27
+ }
28
+ /** Code prompt location */
29
+ export interface CodeFramePosition {
30
+ line: number;
31
+ column?: number;
32
+ }
33
+ /** File options where the code is located */
34
+ export interface CodeFrameFileOption {
35
+ filePath: string;
36
+ }
37
+ /** Code indication options */
38
+ export interface CodeFrameNormalOption {
39
+ filePath: string;
40
+ fileContent: string;
41
+ start?: CodeFramePosition;
42
+ end?: CodeFramePosition;
43
+ }
44
+ /**
45
+ * Code indication options
46
+ * - This type is mainly for compatibility with esbuild.
47
+ */
48
+ export interface CodeFrameLineOption {
49
+ /** File path */
50
+ filePath: string;
51
+ /** Error line text */
52
+ lineText: string;
53
+ /** Starting point */
54
+ start?: CodeFramePosition;
55
+ /** Error character length */
56
+ length?: number;
57
+ }
58
+ export type CodeFrameOption = CodeFrameFileOption | CodeFrameNormalOption | CodeFrameLineOption;
59
+ /** Control item */
60
+ export interface ControllerOption {
61
+ /**
62
+ * Hide stack information
63
+ * - default is `true`
64
+ */
65
+ noStack?: boolean;
66
+ /**
67
+ * Do not display colors
68
+ * - default is `false`
69
+ */
70
+ noColor?: boolean;
71
+ }
72
+ /** repair data */
73
+ export interface FixData {
74
+ /** Modify the starting position of string in the original text. */
75
+ start: number;
76
+ /** Modify the ending position of string in the original text */
77
+ end: number;
78
+ /**
79
+ * Replaced new text
80
+ * - If empty, delete the original text.
81
+ */
82
+ newText?: string;
83
+ /** Has it been fixed */
84
+ isFixed?: boolean;
85
+ }
86
+ /** Error Data */
87
+ export interface DevToolErrorData {
88
+ /** Error number */
89
+ id: number;
90
+ /** Error code */
91
+ code?: string;
92
+ /** Error category */
93
+ category?: string;
94
+ title: string;
95
+ message: string;
96
+ stack?: string;
97
+ fixData?: FixData;
98
+ detail?: any;
99
+ /** Absolute path where the error is located. */
100
+ path?: string;
101
+ /**
102
+ * Error level
103
+ * - default is `'Error'`
104
+ */
105
+ level?: keyof typeof ErrorLevel;
106
+ /** Error prompt */
107
+ hint?: string;
108
+ /** Description link */
109
+ referenceUrl?: string;
110
+ codeFrame?: CodeFrameOption;
111
+ }
112
+ /** Error data */
113
+ export interface DevToolErrorInstance extends DevToolErrorData {
114
+ /** Output stored data */
115
+ toData(): BaseRuleStoreData;
116
+ toString(): string;
117
+ toJSON(): {
118
+ message: string;
119
+ name: string;
120
+ stack?: string;
121
+ };
122
+ /** Set control items */
123
+ setControllerOption(opt: ControllerOption): void;
124
+ /** Set code instructions */
125
+ setCodeFrame(opt: CodeFrameOption): void;
126
+ /** Is the error the same */
127
+ isSame<T extends DevToolErrorInstance>(error: T): boolean;
128
+ }
129
+ export interface DevToolErrorsData {
130
+ errors: DevToolErrorInstance[];
131
+ warnings: DevToolErrorInstance[];
132
+ }
133
+ /** Incorrect data input */
134
+ export type DevToolErrorParams = Omit<NonFunctionProperties<DevToolErrorInstance>, 'message' | 'title' | 'path' | 'id'> & {
135
+ controller?: ControllerOption;
136
+ codeFrame?: CodeFrameOption;
137
+ };
@@ -0,0 +1,30 @@
1
+ /** Esbuild Error */
2
+ export interface Error {
3
+ id: string;
4
+ pluginName: string;
5
+ text: string;
6
+ location: Location | null;
7
+ notes: Note[];
8
+ /**
9
+ * Optional user-specified data that is passed through unmodified. You can
10
+ * use this to stash the original error, for example.
11
+ */
12
+ detail: any;
13
+ }
14
+ interface Note {
15
+ text: string;
16
+ location: Location | null;
17
+ }
18
+ interface Location {
19
+ file: string;
20
+ namespace: string;
21
+ /** 1-based */
22
+ line: number;
23
+ /** 0-based, in bytes */
24
+ column: number;
25
+ /** in bytes */
26
+ length: number;
27
+ lineText: string;
28
+ suggestion: string;
29
+ }
30
+ export {};
@@ -0,0 +1,15 @@
1
+ export * as Manifest from './manifest';
2
+ export * as Esbuild from './esbuild';
3
+ export * as Babel from './babel';
4
+ export * as Common from './common';
5
+ export * as Err from './error';
6
+ export * as Logger from './logger';
7
+ export * as SDK from './sdk';
8
+ export * as Modules from './modules';
9
+ export * as Linter from './linter';
10
+ export * as Rule from './rule';
11
+ export * as Thirdparty from './thirdparty';
12
+ export * as Client from './client';
13
+ export * as Constants from './constants';
14
+ export * as Plugin from './plugin';
15
+ export * as Config from './config';
@@ -0,0 +1,48 @@
1
+ import { RuleMessage, BaseRuleStoreData, RuleStoreDataItem } from '../rule';
2
+ import { ErrorLevel as Severity, Range, FixData } from '../error';
3
+ import { SeverityString } from './rule';
4
+ export { ErrorLevel as Severity } from '../error';
5
+ export type { Range, OffsetRange, Position, FixData } from '../error';
6
+ /** Diagnostic recommendations */
7
+ export interface Suggestion {
8
+ description: string;
9
+ fixData?: FixData;
10
+ }
11
+ /** Error file information */
12
+ export interface ReportDocument {
13
+ /** file path */
14
+ path: string;
15
+ /** Is it a transformed code */
16
+ isTransformed?: boolean;
17
+ /** code content */
18
+ content: string;
19
+ range: Range;
20
+ }
21
+ /** Report erroneous data */
22
+ export interface ReportData {
23
+ /** Error message */
24
+ message: string;
25
+ /** Modify severity dynamically at runtime */
26
+ severity?: SeverityString;
27
+ /** Error file information */
28
+ document?: ReportDocument;
29
+ /** Diagnostic suggestions */
30
+ suggestions?: Suggestion;
31
+ /**
32
+ * Detailed information
33
+ * - Mainly additional data provided to the platform.
34
+ */
35
+ detail?: any;
36
+ }
37
+ export type ReportDetailData<T extends BaseRuleStoreData> = Omit<T, keyof BaseRuleStoreData> & {
38
+ /**
39
+ * Error text
40
+ * - When this is present, Diagnostic ['message'] will be overwritten
41
+ */
42
+ description?: string;
43
+ };
44
+ export interface Diagnostic extends Omit<ReportData, 'severity'>, Pick<RuleMessage, 'category' | 'code'> {
45
+ severity: Severity;
46
+ title: string;
47
+ detail?: RuleStoreDataItem;
48
+ }
@@ -0,0 +1,2 @@
1
+ export * from './diagnostic';
2
+ export * from './rule';
@@ -0,0 +1,105 @@
1
+ import type { ArrayToUnion, UnionToTuple } from '../common';
2
+ import type { ErrorLevel as Severity } from '../error';
3
+ import type { Hooks, RuntimeContext } from '../sdk';
4
+ import type { ReportData, Diagnostic } from './diagnostic';
5
+ import type { RuleMessage } from '../rule';
6
+ /** Error level */
7
+ export type SeverityString = keyof typeof Severity;
8
+ /** Error level */
9
+ export type SeverityInput = SeverityString | 'off' | 'on';
10
+ /** Rule configuration */
11
+ export type DefaultRuleConfig = any;
12
+ export type DefaultRuleTitle = string;
13
+ /** Rule check context */
14
+ export interface RuleCheckerContext<Config = DefaultRuleConfig> extends RuntimeContext {
15
+ ruleConfig: Config;
16
+ /**
17
+ * Report an error
18
+ * @param {any} error - error data
19
+ * @param {any} replacer - replace the original error
20
+ */
21
+ report(error: ReportData, replacer?: any): void;
22
+ }
23
+ /**
24
+ * we shouldn't report any errors when the rule check end, so remove the report function on the context.
25
+ */
26
+ export interface RuleCheckerContextForCheckEnd<Config = DefaultRuleConfig> {
27
+ /**
28
+ * data of the rule.
29
+ */
30
+ data: Omit<RuleCheckerContext<Config>, 'report'>;
31
+ /**
32
+ * the validate result for `all` rules.
33
+ */
34
+ validateResult: ValidateResult;
35
+ /**
36
+ * sdk hooks for rule context when check end.
37
+ *
38
+ * rules checking always run after builder compile done, so it must be a part of SDK.Hooks.
39
+ */
40
+ hooks: Pick<Hooks, 'afterSaveManifest'>;
41
+ }
42
+ export interface InternalRuleCheckerContextForCheckEnd<Config = DefaultRuleConfig> extends Omit<RuleCheckerContextForCheckEnd<Config>, 'data'> {
43
+ data: Omit<RuleCheckerContext<Config>, 'report' | 'ruleConfig'>;
44
+ }
45
+ export type CheckCallback<Config = DefaultRuleConfig> = (context: RuleCheckerContext<Config>) => void | Promise<void>;
46
+ export type OnCheckEndCallback<Config = DefaultRuleConfig> = (context: RuleCheckerContextForCheckEnd<Config>) => void | Promise<void>;
47
+ /** Rule Metadata */
48
+ export interface RuleMeta<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends Pick<RuleMessage, 'code' | 'category'> {
49
+ title: Title;
50
+ severity: Severity;
51
+ /** Detailed document link */
52
+ referenceUrl?: string;
53
+ /** Default configuration */
54
+ defaultConfig?: Config;
55
+ }
56
+ export interface BaseRuleData<Config> {
57
+ check: CheckCallback<Config>;
58
+ /**
59
+ * execute when all rules check end.
60
+ */
61
+ onCheckEnd?: OnCheckEndCallback<Config>;
62
+ }
63
+ /** Rule Data */
64
+ export interface RuleData<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends BaseRuleData<Config> {
65
+ meta: RuleMeta<Config, Title>;
66
+ }
67
+ /** External Rule Metadata */
68
+ export interface ExtendRuleMeta<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends Omit<RuleMeta<Config, Title>, 'severity' | 'code'> {
69
+ severity: SeverityString;
70
+ }
71
+ /** External rule data */
72
+ export interface ExtendRuleData<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends BaseRuleData<Config> {
73
+ meta: ExtendRuleMeta<Config, Title>;
74
+ }
75
+ /** rule constructor */
76
+ export type RuleConstructor<Title extends DefaultRuleTitle, Config = DefaultRuleConfig> = () => RuleData<Config, Title>;
77
+ /** External rule constructor */
78
+ export type ExtendRuleConstructor<Title extends DefaultRuleTitle, Config = DefaultRuleConfig> = () => ExtendRuleData<Config, Title>;
79
+ /** Rule configuration */
80
+ export type RulesMap = Record<string, RuleConfigItem>;
81
+ /** Single rule configuration */
82
+ export type RuleConfigItem<T = unknown> = SeverityInput | [SeverityInput, T];
83
+ /** Verification result */
84
+ export interface ValidateResult {
85
+ errors: Diagnostic[];
86
+ replace: any[];
87
+ }
88
+ /** Verifier options */
89
+ export interface Options<Extends extends ExtendRuleData[] = [], InternalRules extends RuleData[] = [], _Extends = UnionToTuple<ArrayToUnion<[...Extends]>>> {
90
+ rules?: InferRulesConfig<_Extends extends ExtendRuleData[] ? _Extends : Extends> & InferRulesConfig<InternalRules>;
91
+ level?: SeverityString;
92
+ extends?: Extends;
93
+ }
94
+ type InferRuleTitle<T extends ExtendRuleData | RuleData> = T['meta']['title'] extends `${infer R}` ? R : string;
95
+ type InferRulesTitles<T extends (ExtendRuleData | RuleData)[]> = ArrayToUnion<{
96
+ [K in keyof T]: InferRuleTitle<T[K]>;
97
+ }>;
98
+ type InferRuleConfigByTitle<T extends (ExtendRuleData | RuleData)[], Title extends string> = {
99
+ [K in keyof T]: InferRuleTitle<T[K]> extends Title ? InferRuleConfig<T[K]> : never;
100
+ }[number];
101
+ export type InferRuleConfig<T> = T extends ExtendRuleData<infer P1> ? P1 : T extends RuleData<infer P2> ? P2 : any;
102
+ export type InferRulesConfig<T extends (ExtendRuleData | RuleData)[]> = {
103
+ [K in InferRulesTitles<T>]?: RuleConfigItem<InferRuleConfigByTitle<T, K>>;
104
+ } & Record<string, RuleConfigItem | undefined>;
105
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare enum LogLevel {
2
+ Silent = 0,
3
+ Error = 1,
4
+ Warning = 2,
5
+ Info = 3,
6
+ Debug = 4,
7
+ Verbose = 5
8
+ }
9
+ export type LogLevelName = keyof typeof LogLevel;