@visulima/error 4.5.0 → 4.6.0
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/CHANGELOG.md +15 -0
- package/README.md +148 -4
- package/dist/code-frame/index.cjs +6 -5
- package/dist/code-frame/index.mjs +6 -5
- package/dist/error/index.cjs +10 -3
- package/dist/error/index.d.cts +19 -1
- package/dist/error/index.d.mts +19 -1
- package/dist/error/index.d.ts +19 -1
- package/dist/error/index.mjs +6 -3
- package/dist/index.cjs +14 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +10 -7
- package/dist/packem_shared/NonError-BrwMc2LE.mjs +13 -0
- package/dist/packem_shared/NonError-DqwGL5Cy.cjs +15 -0
- package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +32 -0
- package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +39 -0
- package/dist/packem_shared/{aiFinder-BGfwKKxE.cjs → aiFinder-BR9Pq804.cjs} +19 -23
- package/dist/packem_shared/{aiFinder-Bk1vt0_x.mjs → aiFinder-CFHvOjD8.mjs} +19 -23
- package/dist/packem_shared/{aiSolutionResponse-bDi4ad8f.mjs → aiSolutionResponse-BaN1M990.mjs} +3 -2
- package/dist/packem_shared/{aiSolutionResponse-BPckbL56.cjs → aiSolutionResponse-Cqi0mFxy.cjs} +3 -2
- package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +120 -0
- package/dist/packem_shared/deserializeError-DuzHucBb.mjs +118 -0
- package/dist/packem_shared/index-BmoOJLvu.mjs +12 -0
- package/dist/packem_shared/index-C53Tqb7g.cjs +14 -0
- package/dist/packem_shared/{indexToLineColumn-Dx91YDU1.mjs → indexToLineColumn-CKQKtKEK.mjs} +0 -2
- package/dist/packem_shared/{indexToLineColumn-DjmjeiIY.cjs → indexToLineColumn-Cro5eT8v.cjs} +0 -2
- package/dist/packem_shared/{isVisulimaError-BVLWvREw.cjs → isVisulimaError-Bb1_TB6w.cjs} +0 -1
- package/dist/packem_shared/{isVisulimaError-H6TqEA42.mjs → isVisulimaError-zyd80Gui.mjs} +0 -1
- package/dist/packem_shared/{parseStacktrace-BKGoWCwC.mjs → parseStacktrace-BlguTUcF.mjs} +10 -15
- package/dist/packem_shared/{parseStacktrace-6pFoXW43.cjs → parseStacktrace-woJgU2XY.cjs} +10 -15
- package/dist/packem_shared/{renderError-BWpM2m6k.mjs → renderError-Cn8M0fQ3.mjs} +37 -22
- package/dist/packem_shared/{renderError-CXZTAXig.cjs → renderError-n3kXGdYj.cjs} +35 -20
- package/dist/packem_shared/{ruleBasedFinder-BYrndubA.mjs → ruleBasedFinder-Cbmc6N7f.mjs} +1 -1
- package/dist/packem_shared/{ruleBasedFinder-y_-5kbeT.cjs → ruleBasedFinder-CkybTSHw.cjs} +1 -1
- package/dist/packem_shared/{serializeError-DusTUACt.mjs → serializeError-DHIelq5o.mjs} +2 -11
- package/dist/packem_shared/{serializeError-CT7s0Ffk.cjs → serializeError-Dt7oFM2R.cjs} +3 -12
- package/dist/solution/ai/index.cjs +2 -2
- package/dist/solution/ai/index.d.cts +2 -2
- package/dist/solution/ai/index.d.mts +2 -2
- package/dist/solution/ai/index.d.ts +2 -2
- package/dist/solution/ai/index.mjs +2 -2
- package/dist/solution/index.cjs +1 -1
- package/dist/solution/index.mjs +1 -1
- package/dist/stacktrace/index.cjs +1 -1
- package/dist/stacktrace/index.d.cts +2 -2
- package/dist/stacktrace/index.d.mts +2 -2
- package/dist/stacktrace/index.d.ts +2 -2
- package/dist/stacktrace/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ const node_fs = require('node:fs');
|
|
|
5
5
|
const node_os = require('node:os');
|
|
6
6
|
const ai = require('ai');
|
|
7
7
|
const solution_ai_aiPrompt = require('../solution/ai/ai-prompt.cjs');
|
|
8
|
-
const aiSolutionResponse = require('./aiSolutionResponse-
|
|
8
|
+
const aiSolutionResponse = require('./aiSolutionResponse-Cqi0mFxy.cjs');
|
|
9
9
|
|
|
10
10
|
var __defProp$1 = Object.defineProperty;
|
|
11
11
|
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
@@ -142,8 +142,8 @@ const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
|
|
|
142
142
|
const generateCacheKey = /* @__PURE__ */ __name((error, file, temperature) => {
|
|
143
143
|
const keyData = {
|
|
144
144
|
error: {
|
|
145
|
-
name: error.name,
|
|
146
145
|
message: error.message,
|
|
146
|
+
name: error.name,
|
|
147
147
|
stack: error.stack
|
|
148
148
|
},
|
|
149
149
|
file: {
|
|
@@ -162,28 +162,26 @@ const getCacheDirectory = /* @__PURE__ */ __name((directory) => {
|
|
|
162
162
|
}
|
|
163
163
|
return join(node_os.tmpdir(), "visulima-error-cache");
|
|
164
164
|
}, "getCacheDirectory");
|
|
165
|
-
const ensureCacheDirectory = /* @__PURE__ */ __name((
|
|
166
|
-
if (!node_fs.existsSync(
|
|
167
|
-
node_fs.mkdirSync(
|
|
165
|
+
const ensureCacheDirectory = /* @__PURE__ */ __name((cacheDirectory) => {
|
|
166
|
+
if (!node_fs.existsSync(cacheDirectory)) {
|
|
167
|
+
node_fs.mkdirSync(cacheDirectory, { recursive: true });
|
|
168
168
|
}
|
|
169
169
|
}, "ensureCacheDirectory");
|
|
170
|
-
const getCacheFilePath = /* @__PURE__ */ __name((
|
|
171
|
-
return join(cacheDir, `${key}.json`);
|
|
172
|
-
}, "getCacheFilePath");
|
|
170
|
+
const getCacheFilePath = /* @__PURE__ */ __name((cacheDirectory, key) => join(cacheDirectory, `${key}.json`), "getCacheFilePath");
|
|
173
171
|
const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
|
|
174
172
|
try {
|
|
175
173
|
if (!node_fs.existsSync(cacheFilePath)) {
|
|
176
|
-
return
|
|
174
|
+
return void 0;
|
|
177
175
|
}
|
|
178
|
-
const cacheContent = node_fs.readFileSync(cacheFilePath, "
|
|
176
|
+
const cacheContent = node_fs.readFileSync(cacheFilePath, "utf8");
|
|
179
177
|
const cacheEntry = JSON.parse(cacheContent);
|
|
180
178
|
const now = Date.now();
|
|
181
179
|
if (now - cacheEntry.timestamp > ttl) {
|
|
182
|
-
return
|
|
180
|
+
return void 0;
|
|
183
181
|
}
|
|
184
182
|
return cacheEntry.solution;
|
|
185
183
|
} catch {
|
|
186
|
-
return
|
|
184
|
+
return void 0;
|
|
187
185
|
}
|
|
188
186
|
}, "readFromCache");
|
|
189
187
|
const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
|
|
@@ -193,7 +191,7 @@ const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
|
|
|
193
191
|
timestamp: Date.now(),
|
|
194
192
|
ttl
|
|
195
193
|
};
|
|
196
|
-
node_fs.writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "
|
|
194
|
+
node_fs.writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
|
|
197
195
|
} catch {
|
|
198
196
|
}
|
|
199
197
|
}, "writeToCache");
|
|
@@ -203,15 +201,15 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
203
201
|
const cacheOptions = options?.cache;
|
|
204
202
|
const temperature = options?.temperature ?? 0;
|
|
205
203
|
const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
|
|
204
|
+
const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
|
|
206
205
|
if (cacheOptions?.enabled !== false) {
|
|
207
206
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
208
|
-
const
|
|
209
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
207
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
210
208
|
const cachedSolution = readFromCache(cacheFilePath, ttl);
|
|
211
209
|
if (cachedSolution) {
|
|
212
210
|
return cachedSolution;
|
|
213
211
|
}
|
|
214
|
-
ensureCacheDirectory(
|
|
212
|
+
ensureCacheDirectory(cacheDirectory);
|
|
215
213
|
}
|
|
216
214
|
const content = solution_ai_aiPrompt({ applicationType: void 0, error, file });
|
|
217
215
|
try {
|
|
@@ -222,21 +220,20 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
222
220
|
});
|
|
223
221
|
const messageContent = result.text;
|
|
224
222
|
let solution;
|
|
225
|
-
if (
|
|
223
|
+
if (messageContent) {
|
|
226
224
|
solution = {
|
|
227
|
-
body: aiSolutionResponse(
|
|
225
|
+
body: aiSolutionResponse(messageContent),
|
|
228
226
|
header: DEFAULT_HEADER
|
|
229
227
|
};
|
|
230
228
|
} else {
|
|
231
229
|
solution = {
|
|
232
|
-
body: aiSolutionResponse(
|
|
230
|
+
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
233
231
|
header: DEFAULT_HEADER
|
|
234
232
|
};
|
|
235
233
|
}
|
|
236
234
|
if (cacheOptions?.enabled !== false) {
|
|
237
235
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
238
|
-
const
|
|
239
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
236
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
240
237
|
writeToCache(cacheFilePath, solution, ttl);
|
|
241
238
|
}
|
|
242
239
|
return solution;
|
|
@@ -248,8 +245,7 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
248
245
|
};
|
|
249
246
|
if (cacheOptions?.enabled !== false) {
|
|
250
247
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
251
|
-
const
|
|
252
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
248
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
253
249
|
writeToCache(cacheFilePath, solution, ttl);
|
|
254
250
|
}
|
|
255
251
|
return solution;
|
|
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { generateText } from 'ai';
|
|
5
5
|
import aiPrompt from '../solution/ai/ai-prompt.mjs';
|
|
6
|
-
import aiSolutionResponse from './aiSolutionResponse-
|
|
6
|
+
import aiSolutionResponse from './aiSolutionResponse-BaN1M990.mjs';
|
|
7
7
|
|
|
8
8
|
var __defProp$1 = Object.defineProperty;
|
|
9
9
|
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
@@ -140,8 +140,8 @@ const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
|
|
|
140
140
|
const generateCacheKey = /* @__PURE__ */ __name((error, file, temperature) => {
|
|
141
141
|
const keyData = {
|
|
142
142
|
error: {
|
|
143
|
-
name: error.name,
|
|
144
143
|
message: error.message,
|
|
144
|
+
name: error.name,
|
|
145
145
|
stack: error.stack
|
|
146
146
|
},
|
|
147
147
|
file: {
|
|
@@ -160,28 +160,26 @@ const getCacheDirectory = /* @__PURE__ */ __name((directory) => {
|
|
|
160
160
|
}
|
|
161
161
|
return join(tmpdir(), "visulima-error-cache");
|
|
162
162
|
}, "getCacheDirectory");
|
|
163
|
-
const ensureCacheDirectory = /* @__PURE__ */ __name((
|
|
164
|
-
if (!existsSync(
|
|
165
|
-
mkdirSync(
|
|
163
|
+
const ensureCacheDirectory = /* @__PURE__ */ __name((cacheDirectory) => {
|
|
164
|
+
if (!existsSync(cacheDirectory)) {
|
|
165
|
+
mkdirSync(cacheDirectory, { recursive: true });
|
|
166
166
|
}
|
|
167
167
|
}, "ensureCacheDirectory");
|
|
168
|
-
const getCacheFilePath = /* @__PURE__ */ __name((
|
|
169
|
-
return join(cacheDir, `${key}.json`);
|
|
170
|
-
}, "getCacheFilePath");
|
|
168
|
+
const getCacheFilePath = /* @__PURE__ */ __name((cacheDirectory, key) => join(cacheDirectory, `${key}.json`), "getCacheFilePath");
|
|
171
169
|
const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
|
|
172
170
|
try {
|
|
173
171
|
if (!existsSync(cacheFilePath)) {
|
|
174
|
-
return
|
|
172
|
+
return void 0;
|
|
175
173
|
}
|
|
176
|
-
const cacheContent = readFileSync(cacheFilePath, "
|
|
174
|
+
const cacheContent = readFileSync(cacheFilePath, "utf8");
|
|
177
175
|
const cacheEntry = JSON.parse(cacheContent);
|
|
178
176
|
const now = Date.now();
|
|
179
177
|
if (now - cacheEntry.timestamp > ttl) {
|
|
180
|
-
return
|
|
178
|
+
return void 0;
|
|
181
179
|
}
|
|
182
180
|
return cacheEntry.solution;
|
|
183
181
|
} catch {
|
|
184
|
-
return
|
|
182
|
+
return void 0;
|
|
185
183
|
}
|
|
186
184
|
}, "readFromCache");
|
|
187
185
|
const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
|
|
@@ -191,7 +189,7 @@ const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
|
|
|
191
189
|
timestamp: Date.now(),
|
|
192
190
|
ttl
|
|
193
191
|
};
|
|
194
|
-
writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "
|
|
192
|
+
writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
|
|
195
193
|
} catch {
|
|
196
194
|
}
|
|
197
195
|
}, "writeToCache");
|
|
@@ -201,15 +199,15 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
201
199
|
const cacheOptions = options?.cache;
|
|
202
200
|
const temperature = options?.temperature ?? 0;
|
|
203
201
|
const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
|
|
202
|
+
const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
|
|
204
203
|
if (cacheOptions?.enabled !== false) {
|
|
205
204
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
206
|
-
const
|
|
207
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
205
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
208
206
|
const cachedSolution = readFromCache(cacheFilePath, ttl);
|
|
209
207
|
if (cachedSolution) {
|
|
210
208
|
return cachedSolution;
|
|
211
209
|
}
|
|
212
|
-
ensureCacheDirectory(
|
|
210
|
+
ensureCacheDirectory(cacheDirectory);
|
|
213
211
|
}
|
|
214
212
|
const content = aiPrompt({ applicationType: void 0, error, file });
|
|
215
213
|
try {
|
|
@@ -220,21 +218,20 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
220
218
|
});
|
|
221
219
|
const messageContent = result.text;
|
|
222
220
|
let solution;
|
|
223
|
-
if (
|
|
221
|
+
if (messageContent) {
|
|
224
222
|
solution = {
|
|
225
|
-
body: aiSolutionResponse(
|
|
223
|
+
body: aiSolutionResponse(messageContent),
|
|
226
224
|
header: DEFAULT_HEADER
|
|
227
225
|
};
|
|
228
226
|
} else {
|
|
229
227
|
solution = {
|
|
230
|
-
body: aiSolutionResponse(
|
|
228
|
+
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
231
229
|
header: DEFAULT_HEADER
|
|
232
230
|
};
|
|
233
231
|
}
|
|
234
232
|
if (cacheOptions?.enabled !== false) {
|
|
235
233
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
236
|
-
const
|
|
237
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
234
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
238
235
|
writeToCache(cacheFilePath, solution, ttl);
|
|
239
236
|
}
|
|
240
237
|
return solution;
|
|
@@ -246,8 +243,7 @@ const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
|
246
243
|
};
|
|
247
244
|
if (cacheOptions?.enabled !== false) {
|
|
248
245
|
const cacheKey = generateCacheKey(error, file, temperature);
|
|
249
|
-
const
|
|
250
|
-
const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
|
|
246
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
251
247
|
writeToCache(cacheFilePath, solution, ttl);
|
|
252
248
|
}
|
|
253
249
|
return solution;
|
package/dist/packem_shared/{aiSolutionResponse-bDi4ad8f.mjs → aiSolutionResponse-BaN1M990.mjs}
RENAMED
|
@@ -10,14 +10,15 @@ const between = /* @__PURE__ */ __name((start, end, text) => {
|
|
|
10
10
|
if (endPosition === -1) {
|
|
11
11
|
return "";
|
|
12
12
|
}
|
|
13
|
-
return text.
|
|
13
|
+
return text.slice(adjustedStartPosition, endPosition).trim();
|
|
14
14
|
}, "between");
|
|
15
15
|
const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
|
|
16
16
|
const description = between("FIX", "ENDFIX", rawText);
|
|
17
17
|
if (!description) {
|
|
18
18
|
return [
|
|
19
19
|
"No solution found.",
|
|
20
|
-
|
|
20
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
21
|
+
`Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">@visulima/error</a>.`,
|
|
21
22
|
`"${rawText}"`
|
|
22
23
|
].join("</br></br>");
|
|
23
24
|
}
|
package/dist/packem_shared/{aiSolutionResponse-BPckbL56.cjs → aiSolutionResponse-Cqi0mFxy.cjs}
RENAMED
|
@@ -12,14 +12,15 @@ const between = /* @__PURE__ */ __name((start, end, text) => {
|
|
|
12
12
|
if (endPosition === -1) {
|
|
13
13
|
return "";
|
|
14
14
|
}
|
|
15
|
-
return text.
|
|
15
|
+
return text.slice(adjustedStartPosition, endPosition).trim();
|
|
16
16
|
}, "between");
|
|
17
17
|
const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
|
|
18
18
|
const description = between("FIX", "ENDFIX", rawText);
|
|
19
19
|
if (!description) {
|
|
20
20
|
return [
|
|
21
21
|
"No solution found.",
|
|
22
|
-
|
|
22
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
23
|
+
`Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">@visulima/error</a>.`,
|
|
23
24
|
`"${rawText}"`
|
|
24
25
|
].join("</br></br>");
|
|
25
26
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index-C53Tqb7g.cjs');
|
|
4
|
+
const addKnownErrorConstructor = require('./addKnownErrorConstructor-J1_ZUURa.cjs');
|
|
5
|
+
const NonError = require('./NonError-DqwGL5Cy.cjs');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
maxDepth: Number.POSITIVE_INFINITY
|
|
11
|
+
};
|
|
12
|
+
const deserializePlainObject = /* @__PURE__ */ __name((object, options, depth = 0) => {
|
|
13
|
+
if (addKnownErrorConstructor.isErrorLike(object)) {
|
|
14
|
+
return reconstructError(object, options, depth);
|
|
15
|
+
}
|
|
16
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
17
|
+
return new NonError(JSON.stringify(object));
|
|
18
|
+
}
|
|
19
|
+
return new NonError(JSON.stringify(object));
|
|
20
|
+
}, "deserializePlainObject");
|
|
21
|
+
const reconstructAggregateError = /* @__PURE__ */ __name((Constructor, errors, message, options, depth) => {
|
|
22
|
+
const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
|
|
23
|
+
return new Constructor(reconstructedErrors, message);
|
|
24
|
+
}, "reconstructAggregateError");
|
|
25
|
+
const reconstructError = /* @__PURE__ */ __name((serialized, options, depth) => {
|
|
26
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
27
|
+
return new NonError(JSON.stringify(serialized));
|
|
28
|
+
}
|
|
29
|
+
const { cause, errors, message, name, stack, ...properties } = serialized;
|
|
30
|
+
const Constructor = addKnownErrorConstructor.getErrorConstructor(name) || Error;
|
|
31
|
+
const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
|
|
32
|
+
if (!error.name && name) {
|
|
33
|
+
error.name = name;
|
|
34
|
+
}
|
|
35
|
+
if (message !== void 0) {
|
|
36
|
+
error.message = message;
|
|
37
|
+
}
|
|
38
|
+
if (stack) {
|
|
39
|
+
error.stack = stack;
|
|
40
|
+
}
|
|
41
|
+
restoreErrorProperties(error, properties, cause, name, options, depth);
|
|
42
|
+
if (cause !== void 0) {
|
|
43
|
+
error.cause = deserializeValue(cause, options, depth + 1);
|
|
44
|
+
}
|
|
45
|
+
makePropertiesEnumerable(error, serialized);
|
|
46
|
+
return error;
|
|
47
|
+
}, "reconstructError");
|
|
48
|
+
const deserializeValue = /* @__PURE__ */ __name((value, options, depth) => {
|
|
49
|
+
if (index.isPlainObject(value)) {
|
|
50
|
+
return deserializePlainObject(value, options, depth);
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map((item) => deserializeValue(item, options, depth));
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}, "deserializeValue");
|
|
57
|
+
const restoreErrorProperties = /* @__PURE__ */ __name((error, properties, cause, name, options, depth) => {
|
|
58
|
+
const errorCopy = error;
|
|
59
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
60
|
+
if (key === "cause" && cause !== void 0) {
|
|
61
|
+
continue;
|
|
62
|
+
} else if (key === "errors" && name === "AggregateError") {
|
|
63
|
+
continue;
|
|
64
|
+
} else {
|
|
65
|
+
errorCopy[key] = deserializeValue(value, options, depth + 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, "restoreErrorProperties");
|
|
69
|
+
const makePropertiesEnumerable = /* @__PURE__ */ __name((error, serialized) => {
|
|
70
|
+
const errorProperties = /* @__PURE__ */ new Set();
|
|
71
|
+
errorProperties.add("name");
|
|
72
|
+
errorProperties.add("message");
|
|
73
|
+
errorProperties.add("stack");
|
|
74
|
+
for (const key of Object.keys(serialized)) {
|
|
75
|
+
errorProperties.add(key);
|
|
76
|
+
}
|
|
77
|
+
for (const key of errorProperties) {
|
|
78
|
+
if (key in error) {
|
|
79
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
80
|
+
if (descriptor && !descriptor.enumerable) {
|
|
81
|
+
Object.defineProperty(error, key, {
|
|
82
|
+
...descriptor,
|
|
83
|
+
enumerable: true
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, "makePropertiesEnumerable");
|
|
89
|
+
const handlePrimitive = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handlePrimitive");
|
|
90
|
+
const handleArray = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handleArray");
|
|
91
|
+
const handlePlainObject = /* @__PURE__ */ __name((value, config) => {
|
|
92
|
+
if (addKnownErrorConstructor.isErrorLike(value)) {
|
|
93
|
+
return reconstructError(value, config, 0);
|
|
94
|
+
}
|
|
95
|
+
return deserializePlainObject(value, config);
|
|
96
|
+
}, "handlePlainObject");
|
|
97
|
+
const deserialize = /* @__PURE__ */ __name((value, options = {}) => {
|
|
98
|
+
const config = { ...defaultOptions, ...options };
|
|
99
|
+
if (value instanceof Error) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
if (value === null) {
|
|
103
|
+
return handlePrimitive(null);
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
106
|
+
return handlePrimitive(value);
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
return handleArray(value);
|
|
110
|
+
}
|
|
111
|
+
if (addKnownErrorConstructor.isErrorLike(value)) {
|
|
112
|
+
return reconstructError(value, config, 0);
|
|
113
|
+
}
|
|
114
|
+
if (index.isPlainObject(value)) {
|
|
115
|
+
return handlePlainObject(value, config);
|
|
116
|
+
}
|
|
117
|
+
return new NonError(JSON.stringify(value));
|
|
118
|
+
}, "deserialize");
|
|
119
|
+
|
|
120
|
+
module.exports = deserialize;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { i as isPlainObject } from './index-BmoOJLvu.mjs';
|
|
2
|
+
import { isErrorLike, getErrorConstructor } from './addKnownErrorConstructor-DBmmT2OF.mjs';
|
|
3
|
+
import NonError from './NonError-BrwMc2LE.mjs';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
maxDepth: Number.POSITIVE_INFINITY
|
|
9
|
+
};
|
|
10
|
+
const deserializePlainObject = /* @__PURE__ */ __name((object, options, depth = 0) => {
|
|
11
|
+
if (isErrorLike(object)) {
|
|
12
|
+
return reconstructError(object, options, depth);
|
|
13
|
+
}
|
|
14
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
15
|
+
return new NonError(JSON.stringify(object));
|
|
16
|
+
}
|
|
17
|
+
return new NonError(JSON.stringify(object));
|
|
18
|
+
}, "deserializePlainObject");
|
|
19
|
+
const reconstructAggregateError = /* @__PURE__ */ __name((Constructor, errors, message, options, depth) => {
|
|
20
|
+
const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
|
|
21
|
+
return new Constructor(reconstructedErrors, message);
|
|
22
|
+
}, "reconstructAggregateError");
|
|
23
|
+
const reconstructError = /* @__PURE__ */ __name((serialized, options, depth) => {
|
|
24
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
25
|
+
return new NonError(JSON.stringify(serialized));
|
|
26
|
+
}
|
|
27
|
+
const { cause, errors, message, name, stack, ...properties } = serialized;
|
|
28
|
+
const Constructor = getErrorConstructor(name) || Error;
|
|
29
|
+
const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
|
|
30
|
+
if (!error.name && name) {
|
|
31
|
+
error.name = name;
|
|
32
|
+
}
|
|
33
|
+
if (message !== void 0) {
|
|
34
|
+
error.message = message;
|
|
35
|
+
}
|
|
36
|
+
if (stack) {
|
|
37
|
+
error.stack = stack;
|
|
38
|
+
}
|
|
39
|
+
restoreErrorProperties(error, properties, cause, name, options, depth);
|
|
40
|
+
if (cause !== void 0) {
|
|
41
|
+
error.cause = deserializeValue(cause, options, depth + 1);
|
|
42
|
+
}
|
|
43
|
+
makePropertiesEnumerable(error, serialized);
|
|
44
|
+
return error;
|
|
45
|
+
}, "reconstructError");
|
|
46
|
+
const deserializeValue = /* @__PURE__ */ __name((value, options, depth) => {
|
|
47
|
+
if (isPlainObject(value)) {
|
|
48
|
+
return deserializePlainObject(value, options, depth);
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return value.map((item) => deserializeValue(item, options, depth));
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}, "deserializeValue");
|
|
55
|
+
const restoreErrorProperties = /* @__PURE__ */ __name((error, properties, cause, name, options, depth) => {
|
|
56
|
+
const errorCopy = error;
|
|
57
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
58
|
+
if (key === "cause" && cause !== void 0) {
|
|
59
|
+
continue;
|
|
60
|
+
} else if (key === "errors" && name === "AggregateError") {
|
|
61
|
+
continue;
|
|
62
|
+
} else {
|
|
63
|
+
errorCopy[key] = deserializeValue(value, options, depth + 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, "restoreErrorProperties");
|
|
67
|
+
const makePropertiesEnumerable = /* @__PURE__ */ __name((error, serialized) => {
|
|
68
|
+
const errorProperties = /* @__PURE__ */ new Set();
|
|
69
|
+
errorProperties.add("name");
|
|
70
|
+
errorProperties.add("message");
|
|
71
|
+
errorProperties.add("stack");
|
|
72
|
+
for (const key of Object.keys(serialized)) {
|
|
73
|
+
errorProperties.add(key);
|
|
74
|
+
}
|
|
75
|
+
for (const key of errorProperties) {
|
|
76
|
+
if (key in error) {
|
|
77
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
78
|
+
if (descriptor && !descriptor.enumerable) {
|
|
79
|
+
Object.defineProperty(error, key, {
|
|
80
|
+
...descriptor,
|
|
81
|
+
enumerable: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, "makePropertiesEnumerable");
|
|
87
|
+
const handlePrimitive = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handlePrimitive");
|
|
88
|
+
const handleArray = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handleArray");
|
|
89
|
+
const handlePlainObject = /* @__PURE__ */ __name((value, config) => {
|
|
90
|
+
if (isErrorLike(value)) {
|
|
91
|
+
return reconstructError(value, config, 0);
|
|
92
|
+
}
|
|
93
|
+
return deserializePlainObject(value, config);
|
|
94
|
+
}, "handlePlainObject");
|
|
95
|
+
const deserialize = /* @__PURE__ */ __name((value, options = {}) => {
|
|
96
|
+
const config = { ...defaultOptions, ...options };
|
|
97
|
+
if (value instanceof Error) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
if (value === null) {
|
|
101
|
+
return handlePrimitive(null);
|
|
102
|
+
}
|
|
103
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
104
|
+
return handlePrimitive(value);
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
return handleArray(value);
|
|
108
|
+
}
|
|
109
|
+
if (isErrorLike(value)) {
|
|
110
|
+
return reconstructError(value, config, 0);
|
|
111
|
+
}
|
|
112
|
+
if (isPlainObject(value)) {
|
|
113
|
+
return handlePlainObject(value, config);
|
|
114
|
+
}
|
|
115
|
+
return new NonError(JSON.stringify(value));
|
|
116
|
+
}, "deserialize");
|
|
117
|
+
|
|
118
|
+
export { deserialize as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
9
|
+
}
|
|
10
|
+
__name(isPlainObject, "isPlainObject");
|
|
11
|
+
|
|
12
|
+
export { isPlainObject as i };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (typeof value !== "object" || value === null) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const prototype = Object.getPrototypeOf(value);
|
|
10
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
11
|
+
}
|
|
12
|
+
__name(isPlainObject, "isPlainObject");
|
|
13
|
+
|
|
14
|
+
exports.isPlainObject = isPlainObject;
|
package/dist/packem_shared/{indexToLineColumn-Dx91YDU1.mjs → indexToLineColumn-CKQKtKEK.mjs}
RENAMED
|
@@ -38,14 +38,12 @@ const indexToLineColumn = /* @__PURE__ */ __name((input, index, options) => {
|
|
|
38
38
|
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
39
39
|
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
40
40
|
return {
|
|
41
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
42
41
|
column: index - startIndexesOfEachLine[line2] + 1,
|
|
43
42
|
line: line2 + 1
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
45
|
const line = binarySearch(index, input);
|
|
47
46
|
return {
|
|
48
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
49
47
|
column: index - input[line] + 1,
|
|
50
48
|
line: line + 1
|
|
51
49
|
};
|
package/dist/packem_shared/{indexToLineColumn-DjmjeiIY.cjs → indexToLineColumn-Cro5eT8v.cjs}
RENAMED
|
@@ -40,14 +40,12 @@ const indexToLineColumn = /* @__PURE__ */ __name((input, index, options) => {
|
|
|
40
40
|
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
41
41
|
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
42
42
|
return {
|
|
43
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
44
43
|
column: index - startIndexesOfEachLine[line2] + 1,
|
|
45
44
|
line: line2 + 1
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
47
|
const line = binarySearch(index, input);
|
|
49
48
|
return {
|
|
50
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
51
49
|
column: index - input[line] + 1,
|
|
52
50
|
line: line + 1
|
|
53
51
|
};
|