@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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/dist/cjs/errors/index.d.ts +86 -0
  4. package/dist/cjs/errors/index.d.ts.map +1 -0
  5. package/dist/cjs/hooks/HookManager.d.ts +67 -0
  6. package/dist/cjs/hooks/HookManager.d.ts.map +1 -0
  7. package/dist/cjs/hooks/index.d.ts +7 -0
  8. package/dist/cjs/hooks/index.d.ts.map +1 -0
  9. package/dist/cjs/hooks/types.d.ts +26 -0
  10. package/dist/cjs/hooks/types.d.ts.map +1 -0
  11. package/dist/cjs/index.cjs +756 -0
  12. package/dist/cjs/index.d.ts +11 -0
  13. package/dist/cjs/index.d.ts.map +1 -0
  14. package/dist/cjs/interfaces/index.d.ts +56 -0
  15. package/dist/cjs/interfaces/index.d.ts.map +1 -0
  16. package/dist/cjs/logger/index.d.ts +171 -0
  17. package/dist/cjs/logger/index.d.ts.map +1 -0
  18. package/dist/cjs/utils/cache.d.ts +28 -0
  19. package/dist/cjs/utils/cache.d.ts.map +1 -0
  20. package/dist/cjs/utils/index.d.ts +7 -0
  21. package/dist/cjs/utils/index.d.ts.map +1 -0
  22. package/dist/cjs/utils/object.d.ts +52 -0
  23. package/dist/cjs/utils/object.d.ts.map +1 -0
  24. package/dist/cjs/utils/pipeline.d.ts +45 -0
  25. package/dist/cjs/utils/pipeline.d.ts.map +1 -0
  26. package/dist/cjs/webExtStdoutOrigin.d.ts +4 -0
  27. package/dist/cjs/webExtStdoutOrigin.d.ts.map +1 -0
  28. package/dist/esm/errors/index.d.ts +86 -0
  29. package/dist/esm/errors/index.d.ts.map +1 -0
  30. package/dist/esm/hooks/HookManager.d.ts +67 -0
  31. package/dist/esm/hooks/HookManager.d.ts.map +1 -0
  32. package/dist/esm/hooks/index.d.ts +7 -0
  33. package/dist/esm/hooks/index.d.ts.map +1 -0
  34. package/dist/esm/hooks/types.d.ts +26 -0
  35. package/dist/esm/hooks/types.d.ts.map +1 -0
  36. package/dist/esm/index.d.ts +11 -0
  37. package/dist/esm/index.d.ts.map +1 -0
  38. package/dist/esm/index.js +567 -0
  39. package/dist/esm/interfaces/index.d.ts +56 -0
  40. package/dist/esm/interfaces/index.d.ts.map +1 -0
  41. package/dist/esm/logger/index.d.ts +171 -0
  42. package/dist/esm/logger/index.d.ts.map +1 -0
  43. package/dist/esm/utils/cache.d.ts +28 -0
  44. package/dist/esm/utils/cache.d.ts.map +1 -0
  45. package/dist/esm/utils/index.d.ts +7 -0
  46. package/dist/esm/utils/index.d.ts.map +1 -0
  47. package/dist/esm/utils/object.d.ts +52 -0
  48. package/dist/esm/utils/object.d.ts.map +1 -0
  49. package/dist/esm/utils/pipeline.d.ts +45 -0
  50. package/dist/esm/utils/pipeline.d.ts.map +1 -0
  51. package/dist/esm/webExtStdoutOrigin.d.ts +4 -0
  52. package/dist/esm/webExtStdoutOrigin.d.ts.map +1 -0
  53. package/package.json +37 -0
@@ -0,0 +1,567 @@
1
+ import { format } from "node:util";
2
+ import node_path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import cli_table3 from "cli-table3";
5
+ const ANSI_COLORS = {
6
+ ORANGE: "\x1b[38;5;208m",
7
+ DONE: "\x1b[1m\x1b[32m",
8
+ TIME: "\x1b[38;5;245m",
9
+ VALUE: "\x1b[38;5;75m",
10
+ PURPLE: "\x1b[38;5;141m",
11
+ ERROR_BADGE: "\x1b[41m\x1b[93m",
12
+ RED: "\x1b[31m",
13
+ RESET: "\x1b[0m"
14
+ };
15
+ class Logger {
16
+ prefix;
17
+ showTimestamp;
18
+ useColors;
19
+ rawWrites = null;
20
+ constructor(options = {}){
21
+ this.prefix = options.prefix ?? "[Addfox]";
22
+ this.showTimestamp = options.showTimestamp ?? false;
23
+ this.useColors = options.useColors ?? true;
24
+ this.rawWrites = options.rawWrites ?? null;
25
+ }
26
+ setRawWrites(writes) {
27
+ this.rawWrites = writes;
28
+ }
29
+ getWrites() {
30
+ if (this.rawWrites) return this.rawWrites;
31
+ return {
32
+ stdout: process.stdout.write.bind(process.stdout),
33
+ stderr: process.stderr.write.bind(process.stderr)
34
+ };
35
+ }
36
+ formatPrefix() {
37
+ if (!this.useColors) return `${this.prefix} `;
38
+ return `${ANSI_COLORS.ORANGE}${this.prefix}${ANSI_COLORS.RESET} `;
39
+ }
40
+ formatTimestamp() {
41
+ if (!this.showTimestamp) return "";
42
+ const now = new Date();
43
+ const timeStr = now.toLocaleTimeString();
44
+ return this.useColors ? `${ANSI_COLORS.TIME}${timeStr}${ANSI_COLORS.RESET} ` : `${timeStr} `;
45
+ }
46
+ writeLines(stream, text) {
47
+ const w = this.getWrites()[stream];
48
+ const prefix = this.formatPrefix() + this.formatTimestamp();
49
+ for (const line of text.split("\n"))w(prefix + line + "\n", "utf8");
50
+ }
51
+ info(...args) {
52
+ this.writeLines("stdout", format(...args));
53
+ }
54
+ log(...args) {
55
+ this.info(...args);
56
+ }
57
+ success(...args) {
58
+ const text = format(...args);
59
+ const w = this.getWrites().stdout;
60
+ const prefix = this.formatPrefix() + this.formatTimestamp();
61
+ const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
62
+ for (const line of text.split("\n"))w(prefix + donePrefix + line + "\n", "utf8");
63
+ }
64
+ successWithValue(label, value) {
65
+ const w = this.getWrites().stdout;
66
+ const prefix = this.formatPrefix() + this.formatTimestamp();
67
+ const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
68
+ const valueColored = this.useColors ? `${ANSI_COLORS.VALUE}${value}${ANSI_COLORS.RESET}` : value;
69
+ const line = donePrefix + label + " " + valueColored;
70
+ w(prefix + line + "\n", "utf8");
71
+ }
72
+ successWithDuration(message, ms) {
73
+ const timeStr = this.formatDuration(ms);
74
+ const w = this.getWrites().stdout;
75
+ const prefix = this.formatPrefix() + this.formatTimestamp();
76
+ const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
77
+ const timeColored = this.useColors ? `${ANSI_COLORS.TIME}${timeStr}${ANSI_COLORS.RESET}` : timeStr;
78
+ const line = donePrefix + message + " " + timeColored;
79
+ w(prefix + line + "\n", "utf8");
80
+ }
81
+ warn(...args) {
82
+ this.writeLines("stderr", format(...args));
83
+ }
84
+ error(...args) {
85
+ const text = format(...args);
86
+ const w = this.getWrites().stderr;
87
+ const lines = text.split("\n");
88
+ const errorBadge = this.useColors ? `${ANSI_COLORS.ERROR_BADGE} error ${ANSI_COLORS.RESET} ` : " error ";
89
+ const redPrefix = this.useColors ? ANSI_COLORS.RED : "";
90
+ const resetSuffix = this.useColors ? ANSI_COLORS.RESET : "";
91
+ w("\n", "utf8");
92
+ if (lines.length > 0) {
93
+ w(errorBadge + redPrefix + lines[0] + resetSuffix + "\n", "utf8");
94
+ for(let i = 1; i < lines.length; i++)w(redPrefix + lines[i] + resetSuffix + "\n", "utf8");
95
+ }
96
+ w("\n", "utf8");
97
+ }
98
+ writeErrorBlock(lines) {
99
+ const w = this.getWrites().stderr;
100
+ const errorBadge = this.useColors ? `${ANSI_COLORS.ERROR_BADGE} error ${ANSI_COLORS.RESET} ` : " error ";
101
+ const redPrefix = this.useColors ? ANSI_COLORS.RED : "";
102
+ const resetSuffix = this.useColors ? ANSI_COLORS.RESET : "";
103
+ w("\n", "utf8");
104
+ for(let i = 0; i < lines.length; i++){
105
+ const line = lines[i];
106
+ w(0 === i ? errorBadge + redPrefix + line + resetSuffix + "\n" : redPrefix + line + resetSuffix + "\n", "utf8");
107
+ }
108
+ w("\n", "utf8");
109
+ }
110
+ formatDuration(ms) {
111
+ if (ms >= 1000) return (ms / 1000).toFixed(2) + "s";
112
+ return ms + "ms";
113
+ }
114
+ logEntriesTable(entries, options) {
115
+ if (0 === entries.length) return;
116
+ const root = options?.root;
117
+ const headColor = this.useColors ? ANSI_COLORS.PURPLE : "";
118
+ const resetColor = this.useColors ? ANSI_COLORS.RESET : "";
119
+ const table = new cli_table3({
120
+ head: [
121
+ headColor + "Entry" + resetColor,
122
+ headColor + "File" + resetColor
123
+ ],
124
+ style: {
125
+ head: [],
126
+ border: []
127
+ },
128
+ chars: {
129
+ top: "╌",
130
+ "top-mid": "┬",
131
+ "top-left": "┌",
132
+ "top-right": "┐",
133
+ bottom: "╌",
134
+ "bottom-mid": "┴",
135
+ "bottom-left": "└",
136
+ "bottom-right": "┘",
137
+ left: "│",
138
+ "left-mid": "├",
139
+ mid: "╌",
140
+ "mid-mid": "┼",
141
+ right: "│",
142
+ "right-mid": "┤",
143
+ middle: "│"
144
+ }
145
+ });
146
+ for (const e of entries){
147
+ const fileDisplay = void 0 !== root ? this.fileLink(e.scriptPath, node_path.relative(root, e.scriptPath).replace(/\\/g, "/")) : e.scriptPath;
148
+ table.push([
149
+ e.name,
150
+ fileDisplay
151
+ ]);
152
+ }
153
+ const w = this.getWrites().stdout;
154
+ w(table.toString() + "\n", "utf8");
155
+ }
156
+ fileLink(absolutePath, displayText) {
157
+ const url = pathToFileURL(absolutePath).href;
158
+ if (!this.useColors) return displayText;
159
+ return "\x1b]8;;" + url + "\x07" + displayText + "\x1b]8;;\x07";
160
+ }
161
+ }
162
+ const logger = new Logger();
163
+ function log(...args) {
164
+ logger.log(...args);
165
+ }
166
+ function logDone(...args) {
167
+ logger.success(...args);
168
+ }
169
+ function logDoneTimed(message, ms) {
170
+ logger.successWithDuration(message, ms);
171
+ }
172
+ function logDoneWithValue(label, value) {
173
+ logger.successWithValue(label, value);
174
+ }
175
+ function formatDuration(ms) {
176
+ return logger.formatDuration(ms);
177
+ }
178
+ function warn(...args) {
179
+ logger.warn(...args);
180
+ }
181
+ function logger_error(...args) {
182
+ logger.error(...args);
183
+ }
184
+ function writeExtensionErrorBlock(lines) {
185
+ logger.writeErrorBlock(lines);
186
+ }
187
+ function logEntriesTable(entries, options) {
188
+ logger.logEntriesTable(entries, options);
189
+ }
190
+ function setAddfoxLoggerRawWrites(writes) {
191
+ logger.setRawWrites(writes);
192
+ }
193
+ const ADDFOX_ERROR_CODES = {
194
+ CONFIG_NOT_FOUND: "ADDFOX_CONFIG_NOT_FOUND",
195
+ CONFIG_LOAD_FAILED: "ADDFOX_CONFIG_LOAD_FAILED",
196
+ MANIFEST_MISSING: "ADDFOX_MANIFEST_MISSING",
197
+ APP_DIR_MISSING: "ADDFOX_APP_DIR_MISSING",
198
+ NO_ENTRIES: "ADDFOX_NO_ENTRIES",
199
+ ENTRY_SCRIPT_FROM_HTML: "ADDFOX_ENTRY_SCRIPT_FROM_HTML",
200
+ INVALID_BROWSER: "ADDFOX_INVALID_BROWSER",
201
+ UNKNOWN_COMMAND: "ADDFOX_UNKNOWN_COMMAND",
202
+ RSTEST_CONFIG_NOT_FOUND: "ADDFOX_RSTEST_CONFIG_NOT_FOUND",
203
+ RSDOCTOR_NOT_INSTALLED: "ADDFOX_RSDOCTOR_NOT_INSTALLED",
204
+ RSBUILD_CONFIG_ERROR: "ADDFOX_RSBUILD_CONFIG_ERROR",
205
+ BUILD_ERROR: "ADDFOX_BUILD_ERROR",
206
+ ZIP_OUTPUT: "ADDFOX_ZIP_OUTPUT",
207
+ ZIP_ARCHIVE: "ADDFOX_ZIP_ARCHIVE"
208
+ };
209
+ class AddfoxError extends Error {
210
+ code;
211
+ details;
212
+ hint;
213
+ cause;
214
+ constructor(options){
215
+ super(options.message);
216
+ this.name = "AddfoxError";
217
+ this.code = options.code;
218
+ this.details = options.details;
219
+ this.hint = options.hint;
220
+ this.cause = options.cause;
221
+ Object.setPrototypeOf(this, new.target.prototype);
222
+ }
223
+ toJSON() {
224
+ return {
225
+ name: this.name,
226
+ code: this.code,
227
+ message: this.message,
228
+ details: this.details,
229
+ hint: this.hint,
230
+ stack: this.stack,
231
+ cause: this.cause
232
+ };
233
+ }
234
+ format() {
235
+ const parts = [
236
+ `[${this.code}] ${this.message}`
237
+ ];
238
+ if (this.details) parts.push(` Details: ${this.details}`);
239
+ if (this.hint) parts.push(` Hint: ${this.hint}`);
240
+ return parts.join("\n");
241
+ }
242
+ toString() {
243
+ return this.format();
244
+ }
245
+ }
246
+ function createError(code, message, options) {
247
+ return new AddfoxError({
248
+ code,
249
+ message,
250
+ ...options
251
+ });
252
+ }
253
+ function isAddfoxError(error) {
254
+ return error instanceof AddfoxError;
255
+ }
256
+ function formatError(error) {
257
+ if (isAddfoxError(error)) return error.format();
258
+ if (error instanceof Error) return error.stack ?? error.message;
259
+ return String(error);
260
+ }
261
+ function exitWithError(_err, exitCode = 1) {
262
+ process.exit(exitCode);
263
+ }
264
+ function createCache() {
265
+ const store = new Map();
266
+ return {
267
+ get (key) {
268
+ const entry = store.get(key);
269
+ if (!entry) return;
270
+ if (entry.expiresAt && Date.now() > entry.expiresAt) return void store.delete(key);
271
+ return entry.value;
272
+ },
273
+ set (key, value, ttlMs) {
274
+ const entry = {
275
+ value,
276
+ expiresAt: ttlMs ? Date.now() + ttlMs : void 0
277
+ };
278
+ store.set(key, entry);
279
+ },
280
+ has (key) {
281
+ const entry = store.get(key);
282
+ if (!entry) return false;
283
+ if (entry.expiresAt && Date.now() > entry.expiresAt) {
284
+ store.delete(key);
285
+ return false;
286
+ }
287
+ return true;
288
+ },
289
+ delete (key) {
290
+ return store.delete(key);
291
+ },
292
+ clear () {
293
+ store.clear();
294
+ },
295
+ keys () {
296
+ const now = Date.now();
297
+ const keys = [];
298
+ for (const [key, entry] of store)if (!entry.expiresAt || now <= entry.expiresAt) keys.push(key);
299
+ return keys;
300
+ },
301
+ size () {
302
+ return this.keys().length;
303
+ }
304
+ };
305
+ }
306
+ function memoize(fn, keyFn) {
307
+ const cache = createCache();
308
+ return (...args)=>{
309
+ const key = keyFn ? keyFn(...args) : JSON.stringify(args);
310
+ if (cache.has(key)) return cache.get(key);
311
+ const result = fn(...args);
312
+ cache.set(key, result);
313
+ return result;
314
+ };
315
+ }
316
+ function memoizeAsync(fn, keyFn) {
317
+ const cache = createCache();
318
+ const pending = new Map();
319
+ return async (...args)=>{
320
+ const key = keyFn ? keyFn(...args) : JSON.stringify(args);
321
+ if (cache.has(key)) return cache.get(key);
322
+ if (pending.has(key)) return pending.get(key);
323
+ const promise = fn(...args).finally(()=>{
324
+ pending.delete(key);
325
+ });
326
+ pending.set(key, promise);
327
+ const result = await promise;
328
+ cache.set(key, result);
329
+ return result;
330
+ };
331
+ }
332
+ function pipe(...fns) {
333
+ return (x)=>fns.reduce((v, f)=>f(v), x);
334
+ }
335
+ function pipeAsync(...fns) {
336
+ return async (x)=>{
337
+ let result = x;
338
+ for (const fn of fns)result = await fn(result);
339
+ return result;
340
+ };
341
+ }
342
+ function compose(...fns) {
343
+ return (x)=>fns.reduceRight((v, f)=>f(v), x);
344
+ }
345
+ function createPipeline(...steps) {
346
+ return async (input)=>{
347
+ let result = input;
348
+ for (const step of steps)result = await step(result);
349
+ return result;
350
+ };
351
+ }
352
+ function applyMiddleware(value, middlewares) {
353
+ let index = 0;
354
+ function next() {
355
+ if (index >= middlewares.length) return value;
356
+ const middleware = middlewares[index++];
357
+ return middleware(value, next);
358
+ }
359
+ return next();
360
+ }
361
+ function curry(fn) {
362
+ return (a)=>(b)=>fn(a, b);
363
+ }
364
+ function partial(fn, a) {
365
+ return (...rest)=>fn(a, ...rest);
366
+ }
367
+ function tap(fn) {
368
+ return (x)=>{
369
+ fn(x);
370
+ return x;
371
+ };
372
+ }
373
+ function tryCatch(fn, onError) {
374
+ try {
375
+ return fn();
376
+ } catch (error) {
377
+ return onError?.(error);
378
+ }
379
+ }
380
+ async function tryCatchAsync(fn, onError) {
381
+ try {
382
+ return await fn();
383
+ } catch (error) {
384
+ return onError?.(error);
385
+ }
386
+ }
387
+ function deepMerge(target, source) {
388
+ const result = {
389
+ ...target
390
+ };
391
+ for (const key of Object.keys(source)){
392
+ const sourceValue = source[key];
393
+ const targetValue = result[key];
394
+ if (null === sourceValue || 'object' != typeof sourceValue || Array.isArray(sourceValue) || null === targetValue || 'object' != typeof targetValue || Array.isArray(targetValue)) result[key] = sourceValue;
395
+ else result[key] = deepMerge(targetValue, sourceValue);
396
+ }
397
+ return result;
398
+ }
399
+ function pick(obj, keys) {
400
+ const result = {};
401
+ for (const key of keys)if (key in obj) result[key] = obj[key];
402
+ return result;
403
+ }
404
+ function omit(obj, keys) {
405
+ const result = {
406
+ ...obj
407
+ };
408
+ for (const key of keys)delete result[key];
409
+ return result;
410
+ }
411
+ function get(obj, path, defaultValue) {
412
+ const keys = path.split('.');
413
+ let current = obj;
414
+ for (const key of keys){
415
+ if (null == current) return defaultValue;
416
+ current = current[key];
417
+ }
418
+ return current ?? defaultValue;
419
+ }
420
+ function set(obj, path, value) {
421
+ const keys = path.split('.');
422
+ const result = {
423
+ ...obj
424
+ };
425
+ let current = result;
426
+ for(let i = 0; i < keys.length - 1; i++){
427
+ const key = keys[i];
428
+ if (!(key in current) || 'object' != typeof current[key]) current[key] = {};
429
+ current = current[key];
430
+ }
431
+ current[keys[keys.length - 1]] = value;
432
+ return result;
433
+ }
434
+ function has(obj, path) {
435
+ const keys = path.split('.');
436
+ let current = obj;
437
+ for (const key of keys){
438
+ if (null == current || 'object' != typeof current || !(key in current)) return false;
439
+ current = current[key];
440
+ }
441
+ return true;
442
+ }
443
+ function flatten(obj, prefix = '') {
444
+ const result = {};
445
+ for (const [key, value] of Object.entries(obj)){
446
+ const newKey = prefix ? `${prefix}.${key}` : key;
447
+ if (null === value || 'object' != typeof value || Array.isArray(value)) result[newKey] = value;
448
+ else Object.assign(result, flatten(value, newKey));
449
+ }
450
+ return result;
451
+ }
452
+ function unflatten(obj) {
453
+ let result = {};
454
+ for (const [key, value] of Object.entries(obj))result = set(result, key, value);
455
+ return result;
456
+ }
457
+ function filter(obj, predicate) {
458
+ const result = {};
459
+ for (const [key, value] of Object.entries(obj))if (predicate(key, value)) result[key] = value;
460
+ return result;
461
+ }
462
+ function mapValues(obj, fn) {
463
+ const result = {};
464
+ for (const [key, value] of Object.entries(obj))result[key] = fn(value, key);
465
+ return result;
466
+ }
467
+ function isPlainObject(value) {
468
+ if (null === value || 'object' != typeof value) return false;
469
+ const proto = Object.getPrototypeOf(value);
470
+ return null === proto || proto === Object.prototype;
471
+ }
472
+ function isEmpty(value) {
473
+ if (null == value) return true;
474
+ if ('string' == typeof value || Array.isArray(value)) return 0 === value.length;
475
+ if (isPlainObject(value)) return 0 === Object.keys(value).length;
476
+ return false;
477
+ }
478
+ class HookManager {
479
+ registry = new Map();
480
+ options;
481
+ constructor(options = {}){
482
+ this.options = {
483
+ parallel: false,
484
+ bail: false,
485
+ ...options
486
+ };
487
+ }
488
+ register(stage, phase, handler) {
489
+ const key = this.getKey(stage, phase);
490
+ if (!this.registry.has(key)) this.registry.set(key, []);
491
+ const hooks = this.registry.get(key);
492
+ hooks.push(handler);
493
+ return ()=>{
494
+ const index = hooks.indexOf(handler);
495
+ if (index > -1) hooks.splice(index, 1);
496
+ };
497
+ }
498
+ async execute(stage, phase, payload) {
499
+ const key = this.getKey(stage, phase);
500
+ const hooks = this.registry.get(key) || [];
501
+ if (0 === hooks.length) return;
502
+ if (this.options.parallel) if (this.options.bail) await Promise.all(hooks.map((hook)=>hook(payload)));
503
+ else {
504
+ const results = await Promise.allSettled(hooks.map((hook)=>hook(payload)));
505
+ const errors = results.filter((r)=>'rejected' === r.status).map((r)=>r.reason);
506
+ if (errors.length > 0) throw new AggregateError(errors, `Hook execution failed for ${String(stage)}:${phase}`);
507
+ }
508
+ else for (const hook of hooks)try {
509
+ await hook(payload);
510
+ } catch (error) {
511
+ if (this.options.bail) throw error;
512
+ console.error(`Hook error in ${String(stage)}:${phase}:`, error);
513
+ }
514
+ }
515
+ has(stage, phase) {
516
+ const key = this.getKey(stage, phase);
517
+ return (this.registry.get(key)?.length || 0) > 0;
518
+ }
519
+ count(stage, phase) {
520
+ const key = this.getKey(stage, phase);
521
+ return this.registry.get(key)?.length || 0;
522
+ }
523
+ clear(stage, phase) {
524
+ if (void 0 === stage) this.registry.clear();
525
+ else if (void 0 === phase) {
526
+ this.registry.delete(this.getKey(stage, 'before'));
527
+ this.registry.delete(this.getKey(stage, 'after'));
528
+ } else this.registry.delete(this.getKey(stage, phase));
529
+ }
530
+ getKey(stage, phase) {
531
+ return `${String(stage)}:${phase}`;
532
+ }
533
+ for(stage) {
534
+ return new StageHookManager(this, stage);
535
+ }
536
+ }
537
+ class StageHookManager {
538
+ manager;
539
+ stage;
540
+ constructor(manager, stage){
541
+ this.manager = manager;
542
+ this.stage = stage;
543
+ }
544
+ before(handler) {
545
+ return this.manager.register(this.stage, 'before', handler);
546
+ }
547
+ after(handler) {
548
+ return this.manager.register(this.stage, 'after', handler);
549
+ }
550
+ async runBefore(payload) {
551
+ return this.manager.execute(this.stage, 'before', payload);
552
+ }
553
+ async runAfter(payload) {
554
+ return this.manager.execute(this.stage, 'after', payload);
555
+ }
556
+ }
557
+ let webExtStdoutOriginDepth = 0;
558
+ function pushWebExtStdoutOrigin() {
559
+ webExtStdoutOriginDepth += 1;
560
+ }
561
+ function popWebExtStdoutOrigin() {
562
+ webExtStdoutOriginDepth = Math.max(0, webExtStdoutOriginDepth - 1);
563
+ }
564
+ function getWebExtStdoutOriginDepth() {
565
+ return webExtStdoutOriginDepth;
566
+ }
567
+ export { ADDFOX_ERROR_CODES, ANSI_COLORS, AddfoxError, HookManager, Logger, StageHookManager, applyMiddleware, compose, createCache, createError, createPipeline, curry, deepMerge, exitWithError, filter, flatten, formatDuration, formatError, get, getWebExtStdoutOriginDepth, has, isAddfoxError, isEmpty, isPlainObject, log, logDone, logDoneTimed, logDoneWithValue, logEntriesTable, logger, logger_error as error, mapValues, memoize, memoizeAsync, omit, partial, pick, pipe, pipeAsync, popWebExtStdoutOrigin, pushWebExtStdoutOrigin, set, setAddfoxLoggerRawWrites, tap, tryCatch, tryCatchAsync, unflatten, warn, writeExtensionErrorBlock };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Shared types and interfaces
3
+ */
4
+ /** Logger interface (base interface for logging) */
5
+ export interface ILogger {
6
+ debug(message: string, ...args: unknown[]): void;
7
+ info(message: string, ...args: unknown[]): void;
8
+ warn(message: string, ...args: unknown[]): void;
9
+ error(message: string, ...args: unknown[]): void;
10
+ }
11
+ /** @deprecated Use ILogger instead */
12
+ export type Logger = ILogger;
13
+ /** Result type for operations that can fail */
14
+ export interface Result<T, E = Error> {
15
+ success: boolean;
16
+ data?: T;
17
+ error?: E;
18
+ }
19
+ /** Validation result */
20
+ export interface ValidationResult {
21
+ valid: boolean;
22
+ errors: ValidationError[];
23
+ warnings: ValidationWarning[];
24
+ }
25
+ /** Validation error */
26
+ export interface ValidationError {
27
+ code: string;
28
+ message: string;
29
+ path?: string;
30
+ }
31
+ /** Validation warning */
32
+ export interface ValidationWarning {
33
+ code: string;
34
+ message: string;
35
+ path?: string;
36
+ }
37
+ /** Cache entry */
38
+ export interface CacheEntry<T> {
39
+ value: T;
40
+ expiresAt?: number;
41
+ }
42
+ /** Strategy pattern interface */
43
+ export interface Strategy<TInput, TOutput> {
44
+ name: string;
45
+ execute(input: TInput): TOutput | Promise<TOutput>;
46
+ canExecute(input: TInput): boolean;
47
+ }
48
+ /** Builder function type */
49
+ export type Builder<TInput, TOutput, TContext = unknown> = (input: TInput, context: TContext) => TOutput | Promise<TOutput>;
50
+ /** Resolver function type */
51
+ export type Resolver<TInput, TOutput> = (input: TInput) => TOutput | Promise<TOutput>;
52
+ /** Middleware function type */
53
+ export type Middleware<T> = (value: T, next: () => T | Promise<T>) => T | Promise<T>;
54
+ /** Pipeline function type */
55
+ export type Pipeline<TInput, TOutput> = (input: TInput) => Promise<TOutput>;
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oDAAoD;AACpD,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,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