@webneat/codewiki 0.0.1 → 0.0.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/dist/cli/bin.cjs CHANGED
@@ -38,9 +38,65 @@ var import_promises2 = require("fs/promises");
38
38
  var import_path2 = __toESM(require("path"), 1);
39
39
  var import_better_sqlite32 = require("drizzle-orm/better-sqlite3");
40
40
 
41
+ // ../errors/dist/index.js
42
+ function errors(messages) {
43
+ const classes = {};
44
+ for (const name of Object.keys(messages)) {
45
+ classes[name] = class extends Error {
46
+ constructor(details) {
47
+ super(messages[name](details));
48
+ this.details = details;
49
+ this.name = name;
50
+ }
51
+ };
52
+ }
53
+ const any = (value) => value instanceof Error && value.name in classes;
54
+ return {
55
+ any,
56
+ classes,
57
+ new: (name, details) => new classes[name](details),
58
+ is: (name, error) => error instanceof classes[name],
59
+ result: (value) => any(value) ? { success: false, error: value } : { success: true, value },
60
+ or: (value, defaultValue) => any(value) ? defaultValue : value,
61
+ or_throw: (value) => {
62
+ if (any(value)) throw value;
63
+ return value;
64
+ },
65
+ catch: (fn, catch_fn) => {
66
+ catch_fn ??= (e) => e;
67
+ try {
68
+ const res = fn();
69
+ if (res instanceof Promise) return res.catch(catch_fn);
70
+ return res;
71
+ } catch (e) {
72
+ return catch_fn(e);
73
+ }
74
+ },
75
+ safe: (fn, catcher) => {
76
+ return (...args) => {
77
+ try {
78
+ const res = fn(...args);
79
+ if (res instanceof Promise) return res.catch((e) => catcher(e, ...args));
80
+ return res;
81
+ } catch (e) {
82
+ return catcher(e, ...args);
83
+ }
84
+ };
85
+ },
86
+ pipe: (...fns) => {
87
+ let res;
88
+ for (const fn of fns) {
89
+ res = fn(res);
90
+ if (any(res)) return res;
91
+ }
92
+ return res;
93
+ }
94
+ };
95
+ }
96
+ var index_default = errors;
97
+
41
98
  // src/internals/errors.ts
42
- var import_errors = __toESM(require("@webneat/errors"), 1);
43
- var err = (0, import_errors.default)({
99
+ var err = index_default({
44
100
  file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
45
101
  file_not_found: (data) => `File not found: ${data.path}`,
46
102
  db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,