@chainfuse/helpers 3.4.1 → 3.4.3
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/db.mjs +7 -2
- package/dist/net.mjs +68 -19
- package/package.json +4 -4
package/dist/db.mjs
CHANGED
|
@@ -85,7 +85,10 @@ export class SQLCache extends DrizzleCache {
|
|
|
85
85
|
* @returns A `Request` object representing the cache key, constructed with a URL based on the tag or key and the database configuration.
|
|
86
86
|
*/
|
|
87
87
|
getCacheKey(tagOrKey, init) {
|
|
88
|
-
|
|
88
|
+
const headers = new Headers(init?.headers);
|
|
89
|
+
if (!headers.get('Date'))
|
|
90
|
+
headers.set('Date', new Date().toUTCString());
|
|
91
|
+
return new Request(new URL(('tag' in tagOrKey ? ['tag', tagOrKey.tag] : ['key', tagOrKey.key]).join('/'), `https://${this.dbName}.${this.dbType}`), { ...init, headers });
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
94
|
* This function accepts query and parameters that cached into key param, allowing you to retrieve response values for this query from the cache.
|
|
@@ -113,7 +116,9 @@ export class SQLCache extends DrizzleCache {
|
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
else {
|
|
116
|
-
console.
|
|
119
|
+
console.debug('SQLCache.get', 'cache purged', { responseDate });
|
|
120
|
+
await this.cache.then((cache) => cache.delete(cacheKey));
|
|
121
|
+
return undefined;
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
package/dist/net.mjs
CHANGED
|
@@ -69,17 +69,14 @@ export class NetHelpers {
|
|
|
69
69
|
const customHeaders = new Headers(headers);
|
|
70
70
|
if (customHeaders.has('cf-ray')) {
|
|
71
71
|
args.splice(3, 0, customHeaders.get('cf-ray'));
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
82
|
-
.catch(() => { });
|
|
72
|
+
if ('color' in logging && logging.color) {
|
|
73
|
+
await import('chalk')
|
|
74
|
+
.then(({ Chalk }) => new Chalk({ level: 2 }))
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
76
|
+
.then((chalk) => args.splice(3, 1, chalk.rgb(255, 102, 51)(customHeaders.get('cf-ray'))))
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
78
|
+
.catch(() => { });
|
|
79
|
+
}
|
|
83
80
|
}
|
|
84
81
|
if ('custom' in logging && logging.custom) {
|
|
85
82
|
// We faked level 1 as 2 to get headers for ray-id
|
|
@@ -104,8 +101,21 @@ export class NetHelpers {
|
|
|
104
101
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
105
102
|
.map((value) => (value instanceof Date && !isNaN(value.getTime()) ? value.toISOString() : value))
|
|
106
103
|
// Wrap id in brackets
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
.map((value) => {
|
|
105
|
+
if (value === id) {
|
|
106
|
+
const wrappedString = `[${stripAnsi(id)}]`;
|
|
107
|
+
if (logging.color) {
|
|
108
|
+
return chalk.rgb(...Helpers.uniqueIdColor(stripAnsi(id)))(wrappedString);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return wrappedString;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
})
|
|
109
119
|
// Strip out redundant parts of url
|
|
110
120
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
111
121
|
.map((value) => (value === url ? `${customUrl.pathname}${customUrl.search}${customUrl.hash}` : value)));
|
|
@@ -119,8 +129,21 @@ export class NetHelpers {
|
|
|
119
129
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
120
130
|
.map((value) => (value instanceof Date && !isNaN(value.getTime()) ? value.toISOString() : value))
|
|
121
131
|
// Wrap id in brackets
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
.map((value) => {
|
|
133
|
+
if (value === id) {
|
|
134
|
+
const wrappedString = `[${stripAnsi(id)}]`;
|
|
135
|
+
if (logging.color) {
|
|
136
|
+
return chalk.rgb(...Helpers.uniqueIdColor(stripAnsi(id)))(wrappedString);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return wrappedString;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
})
|
|
124
147
|
// Strip out redundant parts of url
|
|
125
148
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
126
149
|
.map((value) => (value === url ? `${customUrl.pathname}${customUrl.search}${customUrl.hash}` : value)));
|
|
@@ -133,8 +156,21 @@ export class NetHelpers {
|
|
|
133
156
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
134
157
|
.map((value) => (value instanceof Date && !isNaN(value.getTime()) ? value.toISOString() : value))
|
|
135
158
|
// Wrap id in brackets
|
|
136
|
-
|
|
137
|
-
|
|
159
|
+
.map((value) => {
|
|
160
|
+
if (value === id) {
|
|
161
|
+
const wrappedString = `[${stripAnsi(id)}]`;
|
|
162
|
+
if (logging.color) {
|
|
163
|
+
return chalk.rgb(...Helpers.uniqueIdColor(stripAnsi(id)))(wrappedString);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
return wrappedString;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
})
|
|
138
174
|
// Strip out redundant parts of url
|
|
139
175
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
140
176
|
.map((value) => (value === url ? `${customUrl.pathname}${customUrl.search}${customUrl.hash}` : value)));
|
|
@@ -147,8 +183,21 @@ export class NetHelpers {
|
|
|
147
183
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
148
184
|
.map((value) => (value instanceof Date && !isNaN(value.getTime()) ? value.toISOString() : value))
|
|
149
185
|
// Wrap id in brackets
|
|
150
|
-
|
|
151
|
-
|
|
186
|
+
.map((value) => {
|
|
187
|
+
if (value === id) {
|
|
188
|
+
const wrappedString = `[${stripAnsi(id)}]`;
|
|
189
|
+
if (logging.color) {
|
|
190
|
+
return chalk.rgb(...Helpers.uniqueIdColor(stripAnsi(id)))(wrappedString);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return wrappedString;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
})
|
|
152
201
|
// Strip out redundant parts of url
|
|
153
202
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
154
203
|
.map((value) => (value === url ? `${customUrl.pathname}${customUrl.search}${customUrl.hash}` : value)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/helpers",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "ChainFuse",
|
|
6
6
|
"homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
|
|
@@ -76,18 +76,18 @@
|
|
|
76
76
|
},
|
|
77
77
|
"prettier": "@demosjarco/prettier-config",
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@chainfuse/types": "^2.10.
|
|
79
|
+
"@chainfuse/types": "^2.10.24",
|
|
80
80
|
"@discordjs/rest": "^2.5.0",
|
|
81
81
|
"chalk": "^5.4.1",
|
|
82
82
|
"cloudflare": "^4.3.0",
|
|
83
83
|
"drizzle-orm": "^0.44.2",
|
|
84
84
|
"strip-ansi": "^7.1.0",
|
|
85
85
|
"uuid": "^11.1.0",
|
|
86
|
-
"zod": "^3.25.
|
|
86
|
+
"zod": "^3.25.63"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@cloudflare/workers-types": "^4.20250610.0",
|
|
90
90
|
"@types/node": "^22.15.31"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "4b4c5f3e940639f1343923f33761367ea32a1e3c"
|
|
93
93
|
}
|