@catbee/utils 2.0.0-next.0 → 2.0.0-next.1
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/README.md +52 -16
- package/array/index.cjs +180 -71
- package/array/index.d.ts +293 -1
- package/array/index.mjs +171 -72
- package/async/index.cjs +92 -36
- package/async/index.d.ts +275 -1
- package/async/index.mjs +92 -36
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +155 -1
- package/cache/index.mjs +2 -2
- package/config/index.cjs +78 -64
- package/config/index.d.ts +64 -2
- package/config/index.mjs +76 -64
- package/context-store/index.d.ts +192 -1
- package/crypto/index.d.ts +163 -1
- package/date/index.cjs +46 -1
- package/date/index.d.ts +190 -1
- package/date/index.mjs +45 -2
- package/decorators/index.cjs +1156 -18
- package/decorators/index.d.ts +684 -1
- package/decorators/index.mjs +1156 -18
- package/dir/index.cjs +4 -3
- package/dir/index.d.ts +195 -1
- package/dir/index.mjs +4 -3
- package/env/index.cjs +10 -26
- package/env/index.d.ts +379 -1
- package/env/index.mjs +10 -26
- package/exception/index.d.ts +232 -1
- package/fs/index.cjs +70 -36
- package/fs/index.d.ts +205 -1
- package/fs/index.mjs +64 -34
- package/http-status-codes/index.d.ts +267 -1
- package/id/index.d.ts +37 -1
- package/index.cjs +3 -3
- package/index.d.ts +1 -1
- package/index.mjs +1 -1
- package/logger/index.cjs +11 -11
- package/logger/index.d.ts +189 -1
- package/logger/index.mjs +12 -12
- package/middleware/index.d.ts +103 -1
- package/obj/index.cjs +150 -162
- package/obj/index.d.ts +136 -1
- package/obj/index.mjs +150 -162
- package/package.json +11 -11
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +138 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +1 -1
- package/request/index.d.ts +241 -2
- package/request/index.mjs +1 -1
- package/response/index.d.ts +318 -2
- package/server/index.cjs +27 -23
- package/server/index.d.ts +785 -4
- package/server/index.mjs +28 -23
- package/stream/index.d.ts +90 -1
- package/string/index.d.ts +102 -1
- package/type/index.cjs +1 -1
- package/type/index.d.ts +107 -1
- package/type/index.mjs +1 -1
- package/types/index.d.ts +774 -4
- package/url/index.cjs +2 -4
- package/url/index.d.ts +142 -1
- package/url/index.mjs +2 -4
- package/{validate → validation}/index.cjs +89 -42
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
- package/{validate → validation}/index.mjs +85 -42
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/decorators.utils.d.ts +0 -705
- package/dir/dir.utils.d.ts +0 -216
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/obj.utils.d.ts +0 -156
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
package/fs/index.mjs
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
26
|
-
import
|
|
25
|
+
import fs from 'fs';
|
|
26
|
+
import fsp from 'fs/promises';
|
|
27
27
|
import { tmpdir } from 'os';
|
|
28
28
|
import path from 'path';
|
|
29
29
|
import { pipeline } from 'stream/promises';
|
|
@@ -33,7 +33,7 @@ var __defProp = Object.defineProperty;
|
|
|
33
33
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
34
34
|
async function fileExists(path2) {
|
|
35
35
|
try {
|
|
36
|
-
await
|
|
36
|
+
await fsp.access(path2);
|
|
37
37
|
return true;
|
|
38
38
|
} catch {
|
|
39
39
|
return false;
|
|
@@ -42,7 +42,7 @@ async function fileExists(path2) {
|
|
|
42
42
|
__name(fileExists, "fileExists");
|
|
43
43
|
async function readJsonFile(path2) {
|
|
44
44
|
try {
|
|
45
|
-
const data = await
|
|
45
|
+
const data = await fsp.readFile(path2, "utf-8");
|
|
46
46
|
return JSON.parse(data);
|
|
47
47
|
} catch {
|
|
48
48
|
return null;
|
|
@@ -56,12 +56,12 @@ async function readJsonOrDefault(path2, defaultValue) {
|
|
|
56
56
|
__name(readJsonOrDefault, "readJsonOrDefault");
|
|
57
57
|
async function writeJsonFile(path2, data, space = 2) {
|
|
58
58
|
const json = JSON.stringify(data, null, space);
|
|
59
|
-
await
|
|
59
|
+
await fsp.writeFile(path2, json, "utf-8");
|
|
60
60
|
}
|
|
61
61
|
__name(writeJsonFile, "writeJsonFile");
|
|
62
62
|
async function deleteFileIfExists(path2) {
|
|
63
63
|
try {
|
|
64
|
-
await
|
|
64
|
+
await fsp.unlink(path2);
|
|
65
65
|
return true;
|
|
66
66
|
} catch (err) {
|
|
67
67
|
if (err.code === "ENOENT") return true;
|
|
@@ -69,36 +69,66 @@ async function deleteFileIfExists(path2) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
__name(deleteFileIfExists, "deleteFileIfExists");
|
|
72
|
-
async function
|
|
72
|
+
async function readFile(path2, encoding = "utf-8") {
|
|
73
|
+
return await fsp.readFile(path2, encoding);
|
|
74
|
+
}
|
|
75
|
+
__name(readFile, "readFile");
|
|
76
|
+
function readFileSync(path2, encoding = "utf-8") {
|
|
77
|
+
return fs.readFileSync(path2, encoding);
|
|
78
|
+
}
|
|
79
|
+
__name(readFileSync, "readFileSync");
|
|
80
|
+
async function safeReadFile(path2, encoding = "utf-8") {
|
|
73
81
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
const data = await fsp.readFile(path2, encoding);
|
|
83
|
+
return {
|
|
84
|
+
data,
|
|
85
|
+
error: null
|
|
86
|
+
};
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return {
|
|
89
|
+
data: null,
|
|
90
|
+
error: new Error(`Failed to read file ${path2}: ${error.message}`)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
__name(safeReadFile, "safeReadFile");
|
|
95
|
+
function safeReadFileSync(path2, encoding = "utf-8") {
|
|
96
|
+
try {
|
|
97
|
+
const data = fs.readFileSync(path2, encoding);
|
|
98
|
+
return {
|
|
99
|
+
data,
|
|
100
|
+
error: null
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return {
|
|
104
|
+
data: null,
|
|
105
|
+
error: new Error(`Failed to read file ${path2}: ${error.message}`)
|
|
106
|
+
};
|
|
77
107
|
}
|
|
78
108
|
}
|
|
79
|
-
__name(
|
|
80
|
-
async function
|
|
109
|
+
__name(safeReadFileSync, "safeReadFileSync");
|
|
110
|
+
async function writeFile(path2, content, encoding = "utf-8") {
|
|
81
111
|
try {
|
|
82
|
-
await
|
|
112
|
+
await fsp.writeFile(path2, content, encoding);
|
|
83
113
|
return true;
|
|
84
114
|
} catch {
|
|
85
115
|
return false;
|
|
86
116
|
}
|
|
87
117
|
}
|
|
88
|
-
__name(
|
|
89
|
-
async function
|
|
118
|
+
__name(writeFile, "writeFile");
|
|
119
|
+
async function appendFile(path2, content, encoding = "utf-8") {
|
|
90
120
|
try {
|
|
91
|
-
await
|
|
121
|
+
await fsp.appendFile(path2, content, encoding);
|
|
92
122
|
return true;
|
|
93
123
|
} catch {
|
|
94
124
|
return false;
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
|
-
__name(
|
|
127
|
+
__name(appendFile, "appendFile");
|
|
98
128
|
async function copyFile(source, destination, overwrite = false) {
|
|
99
129
|
try {
|
|
100
|
-
const flags = overwrite ? 0 :
|
|
101
|
-
await
|
|
130
|
+
const flags = overwrite ? 0 : fsp.constants.COPYFILE_EXCL;
|
|
131
|
+
await fsp.copyFile(source, destination, flags);
|
|
102
132
|
return true;
|
|
103
133
|
} catch {
|
|
104
134
|
return false;
|
|
@@ -107,12 +137,12 @@ async function copyFile(source, destination, overwrite = false) {
|
|
|
107
137
|
__name(copyFile, "copyFile");
|
|
108
138
|
async function moveFile(oldPath, newPath) {
|
|
109
139
|
try {
|
|
110
|
-
await
|
|
140
|
+
await fsp.rename(oldPath, newPath);
|
|
111
141
|
return true;
|
|
112
142
|
} catch {
|
|
113
143
|
try {
|
|
114
|
-
await
|
|
115
|
-
await
|
|
144
|
+
await fsp.copyFile(oldPath, newPath);
|
|
145
|
+
await fsp.unlink(oldPath);
|
|
116
146
|
return true;
|
|
117
147
|
} catch {
|
|
118
148
|
return false;
|
|
@@ -122,7 +152,7 @@ async function moveFile(oldPath, newPath) {
|
|
|
122
152
|
__name(moveFile, "moveFile");
|
|
123
153
|
async function getFileStats(path2) {
|
|
124
154
|
try {
|
|
125
|
-
return await
|
|
155
|
+
return await fsp.stat(path2);
|
|
126
156
|
} catch {
|
|
127
157
|
return null;
|
|
128
158
|
}
|
|
@@ -133,16 +163,16 @@ async function createTempFile({ prefix = "tmp-", extension = "", dir = tmpdir(),
|
|
|
133
163
|
const filename = `${prefix}${randomUUID()}${ext}`;
|
|
134
164
|
const filepath = path.join(dir, filename);
|
|
135
165
|
if (content) {
|
|
136
|
-
await
|
|
166
|
+
await fsp.writeFile(filepath, content);
|
|
137
167
|
} else {
|
|
138
|
-
await
|
|
168
|
+
await fsp.writeFile(filepath, "");
|
|
139
169
|
}
|
|
140
170
|
return filepath;
|
|
141
171
|
}
|
|
142
172
|
__name(createTempFile, "createTempFile");
|
|
143
173
|
async function streamFile(source, destination) {
|
|
144
|
-
const readStream = createReadStream(source);
|
|
145
|
-
const writeStream = createWriteStream(destination);
|
|
174
|
+
const readStream = fs.createReadStream(source);
|
|
175
|
+
const writeStream = fs.createWriteStream(destination);
|
|
146
176
|
try {
|
|
147
177
|
await pipeline(readStream, writeStream);
|
|
148
178
|
} catch (error) {
|
|
@@ -153,7 +183,7 @@ async function streamFile(source, destination) {
|
|
|
153
183
|
}
|
|
154
184
|
__name(streamFile, "streamFile");
|
|
155
185
|
async function readDirectory(dirPath, options = {}) {
|
|
156
|
-
const files = await
|
|
186
|
+
const files = await fsp.readdir(dirPath);
|
|
157
187
|
let result = files;
|
|
158
188
|
if (options.filter) {
|
|
159
189
|
result = result.filter((file) => options.filter.test(file));
|
|
@@ -166,7 +196,7 @@ async function readDirectory(dirPath, options = {}) {
|
|
|
166
196
|
__name(readDirectory, "readDirectory");
|
|
167
197
|
async function createDirectory(dirPath, recursive = true) {
|
|
168
198
|
try {
|
|
169
|
-
await
|
|
199
|
+
await fsp.mkdir(dirPath, {
|
|
170
200
|
recursive
|
|
171
201
|
});
|
|
172
202
|
return true;
|
|
@@ -177,7 +207,7 @@ async function createDirectory(dirPath, recursive = true) {
|
|
|
177
207
|
__name(createDirectory, "createDirectory");
|
|
178
208
|
async function safeReadJsonFile(path2) {
|
|
179
209
|
try {
|
|
180
|
-
const content = await
|
|
210
|
+
const content = await fsp.readFile(path2, "utf-8");
|
|
181
211
|
try {
|
|
182
212
|
const data = JSON.parse(content);
|
|
183
213
|
return {
|
|
@@ -200,7 +230,7 @@ async function safeReadJsonFile(path2) {
|
|
|
200
230
|
__name(safeReadJsonFile, "safeReadJsonFile");
|
|
201
231
|
async function isFile(path2) {
|
|
202
232
|
try {
|
|
203
|
-
const stat = await
|
|
233
|
+
const stat = await fsp.stat(path2);
|
|
204
234
|
return stat.isFile();
|
|
205
235
|
} catch {
|
|
206
236
|
return false;
|
|
@@ -209,7 +239,7 @@ async function isFile(path2) {
|
|
|
209
239
|
__name(isFile, "isFile");
|
|
210
240
|
async function getFileSize(path2) {
|
|
211
241
|
try {
|
|
212
|
-
const stat = await
|
|
242
|
+
const stat = await fsp.stat(path2);
|
|
213
243
|
return stat.size;
|
|
214
244
|
} catch {
|
|
215
245
|
return -1;
|
|
@@ -218,11 +248,11 @@ async function getFileSize(path2) {
|
|
|
218
248
|
__name(getFileSize, "getFileSize");
|
|
219
249
|
async function readFileBuffer(path2) {
|
|
220
250
|
try {
|
|
221
|
-
return await
|
|
251
|
+
return await fsp.readFile(path2);
|
|
222
252
|
} catch {
|
|
223
253
|
return null;
|
|
224
254
|
}
|
|
225
255
|
}
|
|
226
256
|
__name(readFileBuffer, "readFileBuffer");
|
|
227
257
|
|
|
228
|
-
export {
|
|
258
|
+
export { appendFile, copyFile, createDirectory, createTempFile, deleteFileIfExists, fileExists, getFileSize, getFileStats, isFile, moveFile, readDirectory, readFile, readFileBuffer, readFileSync, readJsonFile, readJsonOrDefault, safeReadFile, safeReadFileSync, safeReadJsonFile, streamFile, writeFile, writeJsonFile };
|
|
@@ -22,4 +22,270 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Complete HTTP status codes enum with descriptions.
|
|
27
|
+
* For use with API responses and error handling.
|
|
28
|
+
*/
|
|
29
|
+
declare enum HttpStatusCodes {
|
|
30
|
+
/**
|
|
31
|
+
* The server has received the request headers and the client should proceed to send the request body.
|
|
32
|
+
*/
|
|
33
|
+
CONTINUE = 100,
|
|
34
|
+
/**
|
|
35
|
+
* The server is switching protocols according to the client's request.
|
|
36
|
+
*/
|
|
37
|
+
SWITCHING_PROTOCOLS = 101,
|
|
38
|
+
/**
|
|
39
|
+
* Server has received the request and is still processing it.
|
|
40
|
+
*/
|
|
41
|
+
PROCESSING = 102,
|
|
42
|
+
/**
|
|
43
|
+
* The server is sending preliminary headers while preparing the final response.
|
|
44
|
+
*/
|
|
45
|
+
EARLY_HINTS = 103,
|
|
46
|
+
/**
|
|
47
|
+
* The request succeeded. The result meaning depends on the HTTP method used.
|
|
48
|
+
*/
|
|
49
|
+
OK = 200,
|
|
50
|
+
/**
|
|
51
|
+
* The request succeeded and a new resource was created as a result.
|
|
52
|
+
*/
|
|
53
|
+
CREATED = 201,
|
|
54
|
+
/**
|
|
55
|
+
* The request has been received but not yet acted upon.
|
|
56
|
+
*/
|
|
57
|
+
ACCEPTED = 202,
|
|
58
|
+
/**
|
|
59
|
+
* The returned information is from a third-party source, not the origin server.
|
|
60
|
+
*/
|
|
61
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
62
|
+
/**
|
|
63
|
+
* The request succeeded but there's no content to send in the response.
|
|
64
|
+
*/
|
|
65
|
+
NO_CONTENT = 204,
|
|
66
|
+
/**
|
|
67
|
+
* The client should reset the document view that caused this request.
|
|
68
|
+
*/
|
|
69
|
+
RESET_CONTENT = 205,
|
|
70
|
+
/**
|
|
71
|
+
* The server is delivering only part of the resource due to a range header sent by the client.
|
|
72
|
+
*/
|
|
73
|
+
PARTIAL_CONTENT = 206,
|
|
74
|
+
/**
|
|
75
|
+
* Conveys information about multiple resources, for complex operations.
|
|
76
|
+
*/
|
|
77
|
+
MULTI_STATUS = 207,
|
|
78
|
+
/**
|
|
79
|
+
* The members of a DAV binding have already been enumerated and are not included in the response.
|
|
80
|
+
*/
|
|
81
|
+
ALREADY_REPORTED = 208,
|
|
82
|
+
/**
|
|
83
|
+
* The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
|
|
84
|
+
*/
|
|
85
|
+
IM_USED = 226,
|
|
86
|
+
/**
|
|
87
|
+
* The request has more than one possible response and the client should choose one.
|
|
88
|
+
*/
|
|
89
|
+
MULTIPLE_CHOICES = 300,
|
|
90
|
+
/**
|
|
91
|
+
* The resource has been permanently moved to a new URL.
|
|
92
|
+
*/
|
|
93
|
+
MOVED_PERMANENTLY = 301,
|
|
94
|
+
/**
|
|
95
|
+
* The resource has been temporarily moved to another URL.
|
|
96
|
+
*/
|
|
97
|
+
MOVED_TEMPORARILY = 302,
|
|
98
|
+
/**
|
|
99
|
+
* The response to the request can be found under another URI using the GET method.
|
|
100
|
+
*/
|
|
101
|
+
SEE_OTHER = 303,
|
|
102
|
+
/**
|
|
103
|
+
* The resource hasn't been modified since the last request.
|
|
104
|
+
*/
|
|
105
|
+
NOT_MODIFIED = 304,
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated
|
|
108
|
+
* Response must be accessed through a proxy.
|
|
109
|
+
*/
|
|
110
|
+
USE_PROXY = 305,
|
|
111
|
+
/**
|
|
112
|
+
* The resource is temporarily available at a different URI, using the same HTTP method.
|
|
113
|
+
*/
|
|
114
|
+
TEMPORARY_REDIRECT = 307,
|
|
115
|
+
/**
|
|
116
|
+
* The resource has been permanently moved to another URL, using the same HTTP method.
|
|
117
|
+
*/
|
|
118
|
+
PERMANENT_REDIRECT = 308,
|
|
119
|
+
/**
|
|
120
|
+
* The server cannot process the request due to a client error (malformed request).
|
|
121
|
+
*/
|
|
122
|
+
BAD_REQUEST = 400,
|
|
123
|
+
/**
|
|
124
|
+
* Authentication is required and has failed or not been provided.
|
|
125
|
+
*/
|
|
126
|
+
UNAUTHORIZED = 401,
|
|
127
|
+
/**
|
|
128
|
+
* Reserved for future use, originally intended for digital payment systems.
|
|
129
|
+
*/
|
|
130
|
+
PAYMENT_REQUIRED = 402,
|
|
131
|
+
/**
|
|
132
|
+
* The client doesn't have permission to access the requested resource.
|
|
133
|
+
*/
|
|
134
|
+
FORBIDDEN = 403,
|
|
135
|
+
/**
|
|
136
|
+
* The requested resource could not be found on the server.
|
|
137
|
+
*/
|
|
138
|
+
NOT_FOUND = 404,
|
|
139
|
+
/**
|
|
140
|
+
* The request method is not supported for the requested resource.
|
|
141
|
+
*/
|
|
142
|
+
METHOD_NOT_ALLOWED = 405,
|
|
143
|
+
/**
|
|
144
|
+
* The server can't provide a response matching the list of acceptable values in the client's headers.
|
|
145
|
+
*/
|
|
146
|
+
NOT_ACCEPTABLE = 406,
|
|
147
|
+
/**
|
|
148
|
+
* Authentication by a proxy is required.
|
|
149
|
+
*/
|
|
150
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
151
|
+
/**
|
|
152
|
+
* The server timed out waiting for the request.
|
|
153
|
+
*/
|
|
154
|
+
REQUEST_TIMEOUT = 408,
|
|
155
|
+
/**
|
|
156
|
+
* The request conflicts with the current state of the server.
|
|
157
|
+
*/
|
|
158
|
+
CONFLICT = 409,
|
|
159
|
+
/**
|
|
160
|
+
* The resource has been permanently deleted with no forwarding address.
|
|
161
|
+
*/
|
|
162
|
+
GONE = 410,
|
|
163
|
+
/**
|
|
164
|
+
* The server requires a Content-Length header field.
|
|
165
|
+
*/
|
|
166
|
+
LENGTH_REQUIRED = 411,
|
|
167
|
+
/**
|
|
168
|
+
* Preconditions in the client's headers failed.
|
|
169
|
+
*/
|
|
170
|
+
PRECONDITION_FAILED = 412,
|
|
171
|
+
/**
|
|
172
|
+
* Request entity is larger than limits defined by server.
|
|
173
|
+
*/
|
|
174
|
+
REQUEST_TOO_LONG = 413,
|
|
175
|
+
/**
|
|
176
|
+
* The request payload exceeds server size limits.
|
|
177
|
+
* Modern equivalent of REQUEST_TOO_LONG.
|
|
178
|
+
*/
|
|
179
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
180
|
+
/**
|
|
181
|
+
* The URI requested is too long for the server to interpret.
|
|
182
|
+
*/
|
|
183
|
+
REQUEST_URI_TOO_LONG = 414,
|
|
184
|
+
/**
|
|
185
|
+
* The server does not support the media type requested by the client.
|
|
186
|
+
*/
|
|
187
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
188
|
+
/**
|
|
189
|
+
* The range specified by the Range header cannot be fulfilled.
|
|
190
|
+
*/
|
|
191
|
+
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
192
|
+
/**
|
|
193
|
+
* The server cannot meet the expectations given in the Expect header.
|
|
194
|
+
*/
|
|
195
|
+
EXPECTATION_FAILED = 417,
|
|
196
|
+
/**
|
|
197
|
+
* The server refuses to brew coffee because it is a teapot. (April Fools' joke)
|
|
198
|
+
*/
|
|
199
|
+
IM_A_TEAPOT = 418,
|
|
200
|
+
/**
|
|
201
|
+
* The server cannot store the representation needed to complete the request.
|
|
202
|
+
*/
|
|
203
|
+
INSUFFICIENT_SPACE_ON_RESOURCE = 419,
|
|
204
|
+
/**
|
|
205
|
+
* @deprecated
|
|
206
|
+
* A method has failed - specific to Spring Framework.
|
|
207
|
+
*/
|
|
208
|
+
METHOD_FAILURE = 420,
|
|
209
|
+
/**
|
|
210
|
+
* The server cannot produce a response for the requested URI scheme and authority.
|
|
211
|
+
*/
|
|
212
|
+
MISDIRECTED_REQUEST = 421,
|
|
213
|
+
/**
|
|
214
|
+
* The request was well-formed but has semantic errors preventing processing.
|
|
215
|
+
*/
|
|
216
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
217
|
+
/**
|
|
218
|
+
* The requested resource is locked against access.
|
|
219
|
+
*/
|
|
220
|
+
LOCKED = 423,
|
|
221
|
+
/**
|
|
222
|
+
* The request failed due to the failure of a previous request.
|
|
223
|
+
*/
|
|
224
|
+
FAILED_DEPENDENCY = 424,
|
|
225
|
+
/**
|
|
226
|
+
* The client should switch to a different protocol.
|
|
227
|
+
*/
|
|
228
|
+
UPGRADE_REQUIRED = 426,
|
|
229
|
+
/**
|
|
230
|
+
* The server requires conditional requests to prevent lost updates.
|
|
231
|
+
*/
|
|
232
|
+
PRECONDITION_REQUIRED = 428,
|
|
233
|
+
/**
|
|
234
|
+
* The client has sent too many requests in a given time period (rate limiting).
|
|
235
|
+
*/
|
|
236
|
+
TOO_MANY_REQUESTS = 429,
|
|
237
|
+
/**
|
|
238
|
+
* Request headers are too large for the server to process.
|
|
239
|
+
*/
|
|
240
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
241
|
+
/**
|
|
242
|
+
* Resource cannot be legally provided (e.g., censored by government).
|
|
243
|
+
*/
|
|
244
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
245
|
+
/**
|
|
246
|
+
* The server encountered an unexpected error preventing it from fulfilling the request.
|
|
247
|
+
*/
|
|
248
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
249
|
+
/**
|
|
250
|
+
* The server does not support the functionality required to fulfill the request.
|
|
251
|
+
*/
|
|
252
|
+
NOT_IMPLEMENTED = 501,
|
|
253
|
+
/**
|
|
254
|
+
* The server, acting as a gateway, received an invalid response from an upstream server.
|
|
255
|
+
*/
|
|
256
|
+
BAD_GATEWAY = 502,
|
|
257
|
+
/**
|
|
258
|
+
* The server is currently unable to handle the request due to temporary overload or maintenance.
|
|
259
|
+
*/
|
|
260
|
+
SERVICE_UNAVAILABLE = 503,
|
|
261
|
+
/**
|
|
262
|
+
* The server, acting as a gateway, did not receive a timely response from an upstream server.
|
|
263
|
+
*/
|
|
264
|
+
GATEWAY_TIMEOUT = 504,
|
|
265
|
+
/**
|
|
266
|
+
* The server does not support the HTTP protocol version used in the request.
|
|
267
|
+
*/
|
|
268
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
269
|
+
/**
|
|
270
|
+
* Transparent content negotiation for the request resulted in circular reference.
|
|
271
|
+
*/
|
|
272
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
273
|
+
/**
|
|
274
|
+
* The server cannot store the representation needed to complete the request.
|
|
275
|
+
*/
|
|
276
|
+
INSUFFICIENT_STORAGE = 507,
|
|
277
|
+
/**
|
|
278
|
+
* The server detected an infinite loop while processing the request.
|
|
279
|
+
*/
|
|
280
|
+
LOOP_DETECTED = 508,
|
|
281
|
+
/**
|
|
282
|
+
* Further extensions to the request are required for the server to fulfill it.
|
|
283
|
+
*/
|
|
284
|
+
NOT_EXTENDED = 510,
|
|
285
|
+
/**
|
|
286
|
+
* The client needs to authenticate to gain network access.
|
|
287
|
+
*/
|
|
288
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export { HttpStatusCodes };
|
package/id/index.d.ts
CHANGED
|
@@ -22,4 +22,40 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Generates a UUID v4 string (RFC 4122).
|
|
27
|
+
*
|
|
28
|
+
* @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
|
|
29
|
+
*/
|
|
30
|
+
declare function uuid(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a nanoid-style random ID (URL-safe, customizable length).
|
|
33
|
+
*
|
|
34
|
+
* @param {number} length - Length of the ID (default: 21).
|
|
35
|
+
* @returns {string} Nanoid-style random string.
|
|
36
|
+
*/
|
|
37
|
+
declare function nanoId(length?: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* Generates a cryptographically strong random hex string.
|
|
40
|
+
*
|
|
41
|
+
* @param {number} byteLength - Number of random bytes (default: 16 -> 32 hex chars).
|
|
42
|
+
* @returns {string} Random hex string.
|
|
43
|
+
*/
|
|
44
|
+
declare function randomHex(byteLength?: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Generates a random integer between min (inclusive) and max (inclusive).
|
|
47
|
+
*
|
|
48
|
+
* @param {number} min - Minimum value.
|
|
49
|
+
* @param {number} max - Maximum value.
|
|
50
|
+
* @returns {number} Random integer in range.
|
|
51
|
+
*/
|
|
52
|
+
declare function randomInt(min: number, max: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Generates a cryptographically strong random base64 string.
|
|
55
|
+
*
|
|
56
|
+
* @param {number} byteLength - Number of random bytes (default: 16).
|
|
57
|
+
* @returns {string} Random base64 string (URL-safe, no padding).
|
|
58
|
+
*/
|
|
59
|
+
declare function randomBase64(byteLength?: number): string;
|
|
60
|
+
|
|
61
|
+
export { nanoId, randomBase64, randomHex, randomInt, uuid };
|
package/index.cjs
CHANGED
|
@@ -50,7 +50,7 @@ var stream = require("./stream/index.cjs");
|
|
|
50
50
|
var string = require("./string/index.cjs");
|
|
51
51
|
var type = require("./type/index.cjs");
|
|
52
52
|
var url = require("./url/index.cjs");
|
|
53
|
-
var
|
|
53
|
+
var validation = require("./validation/index.cjs");
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
|
|
@@ -210,9 +210,9 @@ Object.keys(url).forEach(function (k) {
|
|
|
210
210
|
get: function () { return url[k]; }
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
|
-
Object.keys(
|
|
213
|
+
Object.keys(validation).forEach(function (k) {
|
|
214
214
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
215
215
|
enumerable: true,
|
|
216
|
-
get: function () { return
|
|
216
|
+
get: function () { return validation[k]; }
|
|
217
217
|
});
|
|
218
218
|
});
|
package/index.d.ts
CHANGED
package/index.mjs
CHANGED
package/logger/index.cjs
CHANGED
|
@@ -158,8 +158,8 @@ function setupLogger(isGlobal = true) {
|
|
|
158
158
|
...sensitiveFields.flatMap((field) => generateDeepPaths(field, 2))
|
|
159
159
|
]);
|
|
160
160
|
const logParams = {
|
|
161
|
-
name: config.
|
|
162
|
-
level: config.
|
|
161
|
+
name: config.getCatbeeGlobalConfig().logger?.name || "@catbee/utils",
|
|
162
|
+
level: config.getCatbeeGlobalConfig().logger?.level || "info",
|
|
163
163
|
redact: {
|
|
164
164
|
paths: Array.from(paths),
|
|
165
165
|
censor: /* @__PURE__ */ __name((value, path) => redact(value, path), "censor")
|
|
@@ -175,25 +175,25 @@ function setupLogger(isGlobal = true) {
|
|
|
175
175
|
timestamp: pino.stdTimeFunctions.isoTime
|
|
176
176
|
};
|
|
177
177
|
let logger;
|
|
178
|
-
const logDir = config.
|
|
178
|
+
const logDir = config.getCatbeeGlobalConfig().logger?.dir?.trim();
|
|
179
179
|
const hasFileLogging = Boolean(logDir);
|
|
180
|
-
if (hasFileLogging && config.
|
|
180
|
+
if (hasFileLogging && config.getCatbeeGlobalConfig().logger?.pretty) {
|
|
181
181
|
logger = pino__default.default(logParams, pino__default.default.transport({
|
|
182
182
|
targets: [
|
|
183
183
|
{
|
|
184
184
|
target: "pino-pretty",
|
|
185
|
-
level: config.
|
|
185
|
+
level: config.getCatbeeGlobalConfig().logger?.level ?? "info",
|
|
186
186
|
options: {
|
|
187
|
-
colorize: config.
|
|
187
|
+
colorize: config.getCatbeeGlobalConfig().logger?.colorize,
|
|
188
188
|
translateTime: "SYS:standard",
|
|
189
189
|
ignore: "pid,hostname",
|
|
190
|
-
singleLine: config.
|
|
190
|
+
singleLine: config.getCatbeeGlobalConfig().logger?.singleLine,
|
|
191
191
|
levelFirst: true
|
|
192
192
|
}
|
|
193
193
|
},
|
|
194
194
|
{
|
|
195
195
|
target: "pino/file",
|
|
196
|
-
level: config.
|
|
196
|
+
level: config.getCatbeeGlobalConfig().logger?.level ?? "info",
|
|
197
197
|
options: {
|
|
198
198
|
destination: `${logDir}/app.log`,
|
|
199
199
|
mkdir: true
|
|
@@ -209,14 +209,14 @@ function setupLogger(isGlobal = true) {
|
|
|
209
209
|
mkdir: true
|
|
210
210
|
}
|
|
211
211
|
}));
|
|
212
|
-
} else if (config.
|
|
212
|
+
} else if (config.getCatbeeGlobalConfig().logger?.pretty) {
|
|
213
213
|
logger = pino__default.default(logParams, pino__default.default.transport({
|
|
214
214
|
target: "pino-pretty",
|
|
215
215
|
options: {
|
|
216
|
-
colorize: config.
|
|
216
|
+
colorize: config.getCatbeeGlobalConfig().logger?.colorize,
|
|
217
217
|
translateTime: "SYS:standard",
|
|
218
218
|
ignore: "pid,hostname",
|
|
219
|
-
singleLine: config.
|
|
219
|
+
singleLine: config.getCatbeeGlobalConfig().logger?.singleLine,
|
|
220
220
|
levelFirst: true
|
|
221
221
|
}
|
|
222
222
|
}));
|