@addfox/common 0.1.1-beta.2
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 +102 -0
- package/dist/cjs/errors/index.d.ts +86 -0
- package/dist/cjs/errors/index.d.ts.map +1 -0
- package/dist/cjs/hooks/HookManager.d.ts +67 -0
- package/dist/cjs/hooks/HookManager.d.ts.map +1 -0
- package/dist/cjs/hooks/index.d.ts +7 -0
- package/dist/cjs/hooks/index.d.ts.map +1 -0
- package/dist/cjs/hooks/types.d.ts +26 -0
- package/dist/cjs/hooks/types.d.ts.map +1 -0
- package/dist/cjs/index.cjs +756 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/interfaces/index.d.ts +56 -0
- package/dist/cjs/interfaces/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.d.ts +171 -0
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/utils/cache.d.ts +28 -0
- package/dist/cjs/utils/cache.d.ts.map +1 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/object.d.ts +52 -0
- package/dist/cjs/utils/object.d.ts.map +1 -0
- package/dist/cjs/utils/pipeline.d.ts +45 -0
- package/dist/cjs/utils/pipeline.d.ts.map +1 -0
- package/dist/cjs/webExtStdoutOrigin.d.ts +4 -0
- package/dist/cjs/webExtStdoutOrigin.d.ts.map +1 -0
- package/dist/esm/errors/index.d.ts +86 -0
- package/dist/esm/errors/index.d.ts.map +1 -0
- package/dist/esm/hooks/HookManager.d.ts +67 -0
- package/dist/esm/hooks/HookManager.d.ts.map +1 -0
- package/dist/esm/hooks/index.d.ts +7 -0
- package/dist/esm/hooks/index.d.ts.map +1 -0
- package/dist/esm/hooks/types.d.ts +26 -0
- package/dist/esm/hooks/types.d.ts.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +567 -0
- package/dist/esm/interfaces/index.d.ts +56 -0
- package/dist/esm/interfaces/index.d.ts.map +1 -0
- package/dist/esm/logger/index.d.ts +171 -0
- package/dist/esm/logger/index.d.ts.map +1 -0
- package/dist/esm/utils/cache.d.ts +28 -0
- package/dist/esm/utils/cache.d.ts.map +1 -0
- package/dist/esm/utils/index.d.ts +7 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/object.d.ts +52 -0
- package/dist/esm/utils/object.d.ts.map +1 -0
- package/dist/esm/utils/pipeline.d.ts +45 -0
- package/dist/esm/utils/pipeline.d.ts.map +1 -0
- package/dist/esm/webExtStdoutOrigin.d.ts +4 -0
- package/dist/esm/webExtStdoutOrigin.d.ts.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 addfox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @addfox/common
|
|
2
|
+
|
|
3
|
+
Shared utilities for Addfox packages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @addfox/common
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @addfox/common
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Cache Utilities
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createCache, memoize } from '@addfox/common';
|
|
17
|
+
|
|
18
|
+
// Create a cache
|
|
19
|
+
const cache = createCache<string>();
|
|
20
|
+
cache.set('key', 'value', 60000); // 60 second TTL
|
|
21
|
+
const value = cache.get('key');
|
|
22
|
+
|
|
23
|
+
// Memoize a function
|
|
24
|
+
const expensiveFn = memoize((n: number) => n * n);
|
|
25
|
+
expensiveFn(5); // computed
|
|
26
|
+
expensiveFn(5); // cached
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Pipeline Utilities
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { pipe, compose, createPipeline } from '@addfox/common';
|
|
33
|
+
|
|
34
|
+
// Compose functions
|
|
35
|
+
const result = pipe(
|
|
36
|
+
(x: number) => x + 1,
|
|
37
|
+
(x) => x * 2,
|
|
38
|
+
(x) => x.toString()
|
|
39
|
+
)(5); // "12"
|
|
40
|
+
|
|
41
|
+
// Create async pipeline
|
|
42
|
+
const pipeline = createPipeline(
|
|
43
|
+
async (input: string) => input.toUpperCase(),
|
|
44
|
+
async (input) => input.split(''),
|
|
45
|
+
async (input) => input.join('-')
|
|
46
|
+
);
|
|
47
|
+
const result = await pipeline('hello'); // "H-E-L-L-O"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Object Utilities
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { deepMerge, pick, omit, get, set } from '@addfox/common';
|
|
54
|
+
|
|
55
|
+
// Deep merge
|
|
56
|
+
const merged = deepMerge({ a: { b: 1 } }, { a: { c: 2 } });
|
|
57
|
+
// { a: { b: 1, c: 2 } }
|
|
58
|
+
|
|
59
|
+
// Pick/omit properties
|
|
60
|
+
const picked = pick({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { a: 1, c: 3 }
|
|
61
|
+
const omitted = omit({ a: 1, b: 2, c: 3 }, ['b']); // { a: 1, c: 3 }
|
|
62
|
+
|
|
63
|
+
// Get/set nested properties
|
|
64
|
+
const obj = { nested: { value: 42 } };
|
|
65
|
+
const value = get(obj, 'nested.value'); // 42
|
|
66
|
+
const newObj = set(obj, 'nested.other', 100);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Error Utilities
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { AddfoxError, createError, formatError } from '@addfox/common';
|
|
73
|
+
|
|
74
|
+
// Create error
|
|
75
|
+
const error = createError('CONFIG_ERROR', 'Failed to load config', {
|
|
76
|
+
details: 'File not found',
|
|
77
|
+
hint: 'Check the file path',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Format error
|
|
81
|
+
console.log(formatError(error));
|
|
82
|
+
// [CONFIG_ERROR] Failed to load config
|
|
83
|
+
// Details: File not found
|
|
84
|
+
// Hint: Check the file path
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Types
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import type {
|
|
91
|
+
Logger,
|
|
92
|
+
Result,
|
|
93
|
+
ValidationResult,
|
|
94
|
+
Strategy,
|
|
95
|
+
Pipeline,
|
|
96
|
+
Middleware
|
|
97
|
+
} from '@addfox/common';
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @addfox/common/errors
|
|
3
|
+
* Unified error system with error codes and formatting
|
|
4
|
+
*/
|
|
5
|
+
export declare const ADDFOX_ERROR_CODES: {
|
|
6
|
+
readonly CONFIG_NOT_FOUND: "ADDFOX_CONFIG_NOT_FOUND";
|
|
7
|
+
readonly CONFIG_LOAD_FAILED: "ADDFOX_CONFIG_LOAD_FAILED";
|
|
8
|
+
readonly MANIFEST_MISSING: "ADDFOX_MANIFEST_MISSING";
|
|
9
|
+
readonly APP_DIR_MISSING: "ADDFOX_APP_DIR_MISSING";
|
|
10
|
+
readonly NO_ENTRIES: "ADDFOX_NO_ENTRIES";
|
|
11
|
+
readonly ENTRY_SCRIPT_FROM_HTML: "ADDFOX_ENTRY_SCRIPT_FROM_HTML";
|
|
12
|
+
readonly INVALID_BROWSER: "ADDFOX_INVALID_BROWSER";
|
|
13
|
+
readonly UNKNOWN_COMMAND: "ADDFOX_UNKNOWN_COMMAND";
|
|
14
|
+
readonly RSTEST_CONFIG_NOT_FOUND: "ADDFOX_RSTEST_CONFIG_NOT_FOUND";
|
|
15
|
+
readonly RSDOCTOR_NOT_INSTALLED: "ADDFOX_RSDOCTOR_NOT_INSTALLED";
|
|
16
|
+
readonly RSBUILD_CONFIG_ERROR: "ADDFOX_RSBUILD_CONFIG_ERROR";
|
|
17
|
+
readonly BUILD_ERROR: "ADDFOX_BUILD_ERROR";
|
|
18
|
+
readonly ZIP_OUTPUT: "ADDFOX_ZIP_OUTPUT";
|
|
19
|
+
readonly ZIP_ARCHIVE: "ADDFOX_ZIP_ARCHIVE";
|
|
20
|
+
};
|
|
21
|
+
export type AddfoxErrorCode = (typeof ADDFOX_ERROR_CODES)[keyof typeof ADDFOX_ERROR_CODES];
|
|
22
|
+
export interface ErrorOptions {
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
details?: string;
|
|
26
|
+
hint?: string;
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ErrorJSON {
|
|
30
|
+
name: string;
|
|
31
|
+
code: string;
|
|
32
|
+
message: string;
|
|
33
|
+
details?: string;
|
|
34
|
+
hint?: string;
|
|
35
|
+
stack?: string;
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Addfox base error class
|
|
40
|
+
*
|
|
41
|
+
* Provides:
|
|
42
|
+
* - Error code for programmatic handling
|
|
43
|
+
* - Details and hint for user guidance
|
|
44
|
+
* - JSON serialization
|
|
45
|
+
* - Formatted string output
|
|
46
|
+
*/
|
|
47
|
+
export declare class AddfoxError extends Error {
|
|
48
|
+
readonly code: string;
|
|
49
|
+
readonly details?: string;
|
|
50
|
+
readonly hint?: string;
|
|
51
|
+
readonly cause?: unknown;
|
|
52
|
+
constructor(options: ErrorOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Serialize error to JSON
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): ErrorJSON;
|
|
57
|
+
/**
|
|
58
|
+
* Format error for display
|
|
59
|
+
*/
|
|
60
|
+
format(): string;
|
|
61
|
+
/**
|
|
62
|
+
* String representation
|
|
63
|
+
*/
|
|
64
|
+
toString(): string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a generic AddfoxError
|
|
68
|
+
*/
|
|
69
|
+
export declare function createError(code: string, message: string, options?: Omit<ErrorOptions, "code" | "message">): AddfoxError;
|
|
70
|
+
/**
|
|
71
|
+
* Check if value is an AddfoxError
|
|
72
|
+
*/
|
|
73
|
+
export declare function isAddfoxError(error: unknown): error is AddfoxError;
|
|
74
|
+
/**
|
|
75
|
+
* Format any error for display
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatError(error: unknown): string;
|
|
78
|
+
/**
|
|
79
|
+
* Print error to stderr and exit process.
|
|
80
|
+
* Used in CLI top-level catch for clear error reporting.
|
|
81
|
+
*
|
|
82
|
+
* Note: This function should be called from CLI only, as it exits the process.
|
|
83
|
+
* The error display is handled by the caller (CLI) using logger.error().
|
|
84
|
+
*/
|
|
85
|
+
export declare function exitWithError(_err: unknown, exitCode?: number): never;
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;CAerB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAM3F,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAMD;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,YAAY;IAWjC;;OAEG;IACH,MAAM,IAAI,SAAS;IAYnB;;OAEG;IACH,MAAM,IAAI,MAAM;IAOhB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAMD;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,GAC/C,WAAW,CAEb;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQlD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,SAAI,GAAG,KAAK,CAIhE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { HookFunction, HookPhase, HookManagerOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generic hook manager - allows users to define their own stages
|
|
4
|
+
* Only provides before/after hooks for additional code execution
|
|
5
|
+
*/
|
|
6
|
+
export declare class HookManager<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
7
|
+
private registry;
|
|
8
|
+
private options;
|
|
9
|
+
constructor(options?: HookManagerOptions);
|
|
10
|
+
/**
|
|
11
|
+
* Register a hook for a specific stage and phase
|
|
12
|
+
* @param stage - The stage name (user-defined)
|
|
13
|
+
* @param phase - 'before' or 'after'
|
|
14
|
+
* @param handler - The hook function
|
|
15
|
+
* @returns Unregister function
|
|
16
|
+
*/
|
|
17
|
+
register<K extends keyof T>(stage: K, phase: HookPhase, handler: HookFunction<T[K]>): () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Execute hooks for a specific stage and phase
|
|
20
|
+
* @param stage - The stage name
|
|
21
|
+
* @param phase - 'before' or 'after'
|
|
22
|
+
* @param payload - Data passed to hooks
|
|
23
|
+
*/
|
|
24
|
+
execute<K extends keyof T>(stage: K, phase: HookPhase, payload: T[K]): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if hooks exist for a stage/phase
|
|
27
|
+
*/
|
|
28
|
+
has<K extends keyof T>(stage: K, phase: HookPhase): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get number of registered hooks for a stage/phase
|
|
31
|
+
*/
|
|
32
|
+
count<K extends keyof T>(stage: K, phase: HookPhase): number;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all hooks for a stage/phase, or all hooks if no stage specified
|
|
35
|
+
*/
|
|
36
|
+
clear<K extends keyof T>(stage?: K, phase?: HookPhase): void;
|
|
37
|
+
private getKey;
|
|
38
|
+
/**
|
|
39
|
+
* Get a scoped hook manager for a specific stage
|
|
40
|
+
*/
|
|
41
|
+
for<K extends keyof T>(stage: K): StageHookManager<T, K>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Scoped hook manager for a specific stage
|
|
45
|
+
*/
|
|
46
|
+
export declare class StageHookManager<T extends Record<string, unknown>, K extends keyof T> {
|
|
47
|
+
private manager;
|
|
48
|
+
private stage;
|
|
49
|
+
constructor(manager: HookManager<T>, stage: K);
|
|
50
|
+
/**
|
|
51
|
+
* Register a 'before' hook
|
|
52
|
+
*/
|
|
53
|
+
before(handler: HookFunction<T[K]>): () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Register an 'after' hook
|
|
56
|
+
*/
|
|
57
|
+
after(handler: HookFunction<T[K]>): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Execute 'before' hooks
|
|
60
|
+
*/
|
|
61
|
+
runBefore(payload: T[K]): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Execute 'after' hooks
|
|
64
|
+
*/
|
|
65
|
+
runAfter(payload: T[K]): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=HookManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/HookManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClF,OAAO,CAAC,QAAQ,CAAmD;IACnE,OAAO,CAAC,OAAO,CAAqB;gBAExB,OAAO,GAAE,kBAAuB;IAQ5C;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,EACxB,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1B,MAAM,IAAI;IAmBb;;;;;OAKG;IACG,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,GACZ,OAAO,CAAC,IAAI,CAAC;IAoChB;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO;IAK3D;;OAEG;IACH,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM;IAK5D;;OAEG;IACH,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,IAAI;IAW5D,OAAO,CAAC,MAAM;IAId;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;CAGzD;AAED;;GAEG;AACH,qBAAa,gBAAgB,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC;IAGf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,KAAK;gBADL,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,KAAK,EAAE,CAAC;IAGlB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAI/C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAI9C;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic hook system - allows users to define their own stages
|
|
3
|
+
* Provides only before/after hooks for additional code execution
|
|
4
|
+
*/
|
|
5
|
+
export { HookManager, StageHookManager } from './HookManager.js';
|
|
6
|
+
export type { HookFunction, HookRegistry, HookPhase, HookDescriptor, HookManagerOptions, } from './types.ts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACjE,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,cAAc,EACd,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook types for the generic hook system
|
|
3
|
+
*/
|
|
4
|
+
/** Base hook function type */
|
|
5
|
+
export type HookFunction<T = void> = T extends void ? () => void | Promise<void> : (payload: T) => void | Promise<void>;
|
|
6
|
+
/** Hook registry - stores hooks by name */
|
|
7
|
+
export type HookRegistry<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
8
|
+
[K in keyof T]?: Array<HookFunction<T[K]>>;
|
|
9
|
+
};
|
|
10
|
+
/** Hook phase types */
|
|
11
|
+
export type HookPhase = 'before' | 'after';
|
|
12
|
+
/** Hook descriptor */
|
|
13
|
+
export interface HookDescriptor<T = unknown> {
|
|
14
|
+
name: string;
|
|
15
|
+
phase: HookPhase;
|
|
16
|
+
handler: HookFunction<T>;
|
|
17
|
+
priority?: number;
|
|
18
|
+
}
|
|
19
|
+
/** Hook manager options */
|
|
20
|
+
export interface HookManagerOptions {
|
|
21
|
+
/** Whether to run hooks in parallel (default: false - sequential) */
|
|
22
|
+
parallel?: boolean;
|
|
23
|
+
/** Whether to stop on first error (default: false) */
|
|
24
|
+
bail?: boolean;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,8BAA8B;AAC9B,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC1B,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzC,2CAA2C;AAC3C,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACrF,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3C,CAAC;AAEF,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE3C,sBAAsB;AACtB,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,2BAA2B;AAC3B,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
|