@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 +58 -2
- package/dist/cli/bin.cjs.map +1 -1
- package/dist/cli/bin.js +58 -2
- package/dist/cli/bin.js.map +1 -1
- package/dist/cli/index.cjs +58 -2
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +58 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +58 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -21,9 +21,65 @@ import { readFile as readFile2 } from "fs/promises";
|
|
|
21
21
|
import path, { dirname, join as join2 } from "path";
|
|
22
22
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
23
23
|
|
|
24
|
+
// ../errors/dist/index.js
|
|
25
|
+
function errors(messages) {
|
|
26
|
+
const classes = {};
|
|
27
|
+
for (const name of Object.keys(messages)) {
|
|
28
|
+
classes[name] = class extends Error {
|
|
29
|
+
constructor(details) {
|
|
30
|
+
super(messages[name](details));
|
|
31
|
+
this.details = details;
|
|
32
|
+
this.name = name;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const any = (value) => value instanceof Error && value.name in classes;
|
|
37
|
+
return {
|
|
38
|
+
any,
|
|
39
|
+
classes,
|
|
40
|
+
new: (name, details) => new classes[name](details),
|
|
41
|
+
is: (name, error) => error instanceof classes[name],
|
|
42
|
+
result: (value) => any(value) ? { success: false, error: value } : { success: true, value },
|
|
43
|
+
or: (value, defaultValue) => any(value) ? defaultValue : value,
|
|
44
|
+
or_throw: (value) => {
|
|
45
|
+
if (any(value)) throw value;
|
|
46
|
+
return value;
|
|
47
|
+
},
|
|
48
|
+
catch: (fn, catch_fn) => {
|
|
49
|
+
catch_fn ??= (e) => e;
|
|
50
|
+
try {
|
|
51
|
+
const res = fn();
|
|
52
|
+
if (res instanceof Promise) return res.catch(catch_fn);
|
|
53
|
+
return res;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return catch_fn(e);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
safe: (fn, catcher) => {
|
|
59
|
+
return (...args) => {
|
|
60
|
+
try {
|
|
61
|
+
const res = fn(...args);
|
|
62
|
+
if (res instanceof Promise) return res.catch((e) => catcher(e, ...args));
|
|
63
|
+
return res;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return catcher(e, ...args);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
pipe: (...fns) => {
|
|
70
|
+
let res;
|
|
71
|
+
for (const fn of fns) {
|
|
72
|
+
res = fn(res);
|
|
73
|
+
if (any(res)) return res;
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var index_default = errors;
|
|
80
|
+
|
|
24
81
|
// src/internals/errors.ts
|
|
25
|
-
|
|
26
|
-
var err = create_errors({
|
|
82
|
+
var err = index_default({
|
|
27
83
|
file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
|
|
28
84
|
file_not_found: (data) => `File not found: ${data.path}`,
|
|
29
85
|
db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,
|