@saptools/cf-inspector 0.3.8 → 0.3.9
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 +3 -1
- package/dist/cli.js +58 -23
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +54 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -245,6 +245,7 @@ declare function getProperties(session: InspectorSession, objectId: string): Pro
|
|
|
245
245
|
interface CaptureSnapshotOptions {
|
|
246
246
|
readonly captures?: readonly string[];
|
|
247
247
|
readonly includeScopes?: boolean;
|
|
248
|
+
readonly maxValueLength?: number;
|
|
248
249
|
}
|
|
249
250
|
declare function captureSnapshot(session: InspectorSession, pause: PauseEvent, options?: CaptureSnapshotOptions): Promise<SnapshotCaptureResult>;
|
|
250
251
|
|
package/dist/index.js
CHANGED
|
@@ -923,11 +923,12 @@ async function getProperties(session, objectId) {
|
|
|
923
923
|
}
|
|
924
924
|
|
|
925
925
|
// src/snapshot.ts
|
|
926
|
+
init_types();
|
|
926
927
|
var MAX_SCOPES = 3;
|
|
927
928
|
var MAX_SCOPE_VARIABLES = 20;
|
|
928
929
|
var MAX_CHILD_VARIABLES = 8;
|
|
929
930
|
var MAX_VARIABLE_DEPTH = 2;
|
|
930
|
-
var
|
|
931
|
+
var DEFAULT_MAX_VALUE_LENGTH = 4096;
|
|
931
932
|
var PRIORITY_BY_TYPE = {
|
|
932
933
|
local: 0,
|
|
933
934
|
arguments: 1,
|
|
@@ -988,16 +989,28 @@ function formatPrimitive(value) {
|
|
|
988
989
|
}
|
|
989
990
|
return String(value);
|
|
990
991
|
}
|
|
991
|
-
function
|
|
992
|
-
if (
|
|
992
|
+
function resolveMaxValueLength(value) {
|
|
993
|
+
if (value === void 0) {
|
|
994
|
+
return DEFAULT_MAX_VALUE_LENGTH;
|
|
995
|
+
}
|
|
996
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
997
|
+
throw new CfInspectorError(
|
|
998
|
+
"INVALID_ARGUMENT",
|
|
999
|
+
`Invalid maxValueLength: ${value.toString()} \u2014 expected a positive integer`
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
return value;
|
|
1003
|
+
}
|
|
1004
|
+
function limitValueLength(raw, maxValueLength = DEFAULT_MAX_VALUE_LENGTH) {
|
|
1005
|
+
if (raw.length <= maxValueLength) {
|
|
993
1006
|
return raw;
|
|
994
1007
|
}
|
|
995
|
-
return `${raw.slice(0,
|
|
1008
|
+
return `${raw.slice(0, maxValueLength)}...`;
|
|
996
1009
|
}
|
|
997
1010
|
function isExpandable(type) {
|
|
998
1011
|
return type === "object" || type === "function";
|
|
999
1012
|
}
|
|
1000
|
-
async function captureProperties(session, objectId, limit, depth) {
|
|
1013
|
+
async function captureProperties(session, objectId, limit, depth, maxValueLength) {
|
|
1001
1014
|
const properties = await getProperties(session, objectId);
|
|
1002
1015
|
const limited = properties.slice(0, limit);
|
|
1003
1016
|
const variables = await Promise.all(
|
|
@@ -1011,7 +1024,8 @@ async function captureProperties(session, objectId, limit, depth) {
|
|
|
1011
1024
|
session,
|
|
1012
1025
|
described.objectId,
|
|
1013
1026
|
MAX_CHILD_VARIABLES,
|
|
1014
|
-
depth - 1
|
|
1027
|
+
depth - 1,
|
|
1028
|
+
maxValueLength
|
|
1015
1029
|
);
|
|
1016
1030
|
if (nested.length > 0) {
|
|
1017
1031
|
children = nested;
|
|
@@ -1019,7 +1033,7 @@ async function captureProperties(session, objectId, limit, depth) {
|
|
|
1019
1033
|
} catch {
|
|
1020
1034
|
}
|
|
1021
1035
|
}
|
|
1022
|
-
const sanitizedValue = limitValueLength(described.value);
|
|
1036
|
+
const sanitizedValue = limitValueLength(described.value, maxValueLength);
|
|
1023
1037
|
const base = { name, value: sanitizedValue };
|
|
1024
1038
|
const withType = described.type === void 0 ? base : { ...base, type: described.type };
|
|
1025
1039
|
return children === void 0 ? withType : { ...withType, children };
|
|
@@ -1034,7 +1048,7 @@ function selectScopes(scopeChain) {
|
|
|
1034
1048
|
function priorityOf(type) {
|
|
1035
1049
|
return PRIORITY_BY_TYPE[type] ?? Number.MAX_SAFE_INTEGER;
|
|
1036
1050
|
}
|
|
1037
|
-
async function captureScopes(session, frame) {
|
|
1051
|
+
async function captureScopes(session, frame, maxValueLength) {
|
|
1038
1052
|
const scopes = selectScopes(frame.scopeChain);
|
|
1039
1053
|
return await Promise.all(
|
|
1040
1054
|
scopes.map(async (scope) => {
|
|
@@ -1043,7 +1057,13 @@ async function captureScopes(session, frame) {
|
|
|
1043
1057
|
return { type: scope.type, variables: [] };
|
|
1044
1058
|
}
|
|
1045
1059
|
try {
|
|
1046
|
-
const variables = await captureProperties(
|
|
1060
|
+
const variables = await captureProperties(
|
|
1061
|
+
session,
|
|
1062
|
+
objectId,
|
|
1063
|
+
MAX_SCOPE_VARIABLES,
|
|
1064
|
+
MAX_VARIABLE_DEPTH,
|
|
1065
|
+
maxValueLength
|
|
1066
|
+
);
|
|
1047
1067
|
return { type: scope.type, variables };
|
|
1048
1068
|
} catch {
|
|
1049
1069
|
return { type: scope.type, variables: [] };
|
|
@@ -1051,10 +1071,10 @@ async function captureScopes(session, frame) {
|
|
|
1051
1071
|
})
|
|
1052
1072
|
);
|
|
1053
1073
|
}
|
|
1054
|
-
function evalResultToCaptured(expression, result) {
|
|
1074
|
+
function evalResultToCaptured(expression, result, maxValueLength = DEFAULT_MAX_VALUE_LENGTH) {
|
|
1055
1075
|
if (result.exceptionDetails !== void 0) {
|
|
1056
1076
|
const text = typeof result.exceptionDetails.exception?.description === "string" ? result.exceptionDetails.exception.description : typeof result.exceptionDetails.text === "string" ? result.exceptionDetails.text : "evaluation failed";
|
|
1057
|
-
return { expression, error: limitValueLength(text) };
|
|
1077
|
+
return { expression, error: limitValueLength(text, maxValueLength) };
|
|
1058
1078
|
}
|
|
1059
1079
|
const inner = result.result;
|
|
1060
1080
|
if (!inner) {
|
|
@@ -1062,7 +1082,7 @@ function evalResultToCaptured(expression, result) {
|
|
|
1062
1082
|
}
|
|
1063
1083
|
const type = typeof inner.type === "string" ? inner.type : void 0;
|
|
1064
1084
|
const buildCaptured = (rendered) => {
|
|
1065
|
-
const sanitized = limitValueLength(rendered);
|
|
1085
|
+
const sanitized = limitValueLength(rendered, maxValueLength);
|
|
1066
1086
|
const base = { expression, value: sanitized };
|
|
1067
1087
|
return type === void 0 ? base : { ...base, type };
|
|
1068
1088
|
};
|
|
@@ -1157,9 +1177,15 @@ function toStructuredValue(variable) {
|
|
|
1157
1177
|
}
|
|
1158
1178
|
return out;
|
|
1159
1179
|
}
|
|
1160
|
-
async function renderObjectCapture(session, objectId) {
|
|
1180
|
+
async function renderObjectCapture(session, objectId, maxValueLength) {
|
|
1161
1181
|
try {
|
|
1162
|
-
const properties = await captureProperties(
|
|
1182
|
+
const properties = await captureProperties(
|
|
1183
|
+
session,
|
|
1184
|
+
objectId,
|
|
1185
|
+
MAX_SCOPE_VARIABLES,
|
|
1186
|
+
MAX_VARIABLE_DEPTH,
|
|
1187
|
+
maxValueLength
|
|
1188
|
+
);
|
|
1163
1189
|
const structured = {};
|
|
1164
1190
|
for (const variable of properties) {
|
|
1165
1191
|
structured[variable.name] = toStructuredValue(variable);
|
|
@@ -1178,7 +1204,7 @@ function normalizeRenderedObjectCapture(rendered, original) {
|
|
|
1178
1204
|
}
|
|
1179
1205
|
return rendered;
|
|
1180
1206
|
}
|
|
1181
|
-
async function withSerializedObjectCapture(session, expression, evalResult, captured) {
|
|
1207
|
+
async function withSerializedObjectCapture(session, expression, evalResult, captured, maxValueLength) {
|
|
1182
1208
|
if (captured.error !== void 0 || captured.value === void 0) {
|
|
1183
1209
|
return captured;
|
|
1184
1210
|
}
|
|
@@ -1186,7 +1212,7 @@ async function withSerializedObjectCapture(session, expression, evalResult, capt
|
|
|
1186
1212
|
if (objectId === void 0) {
|
|
1187
1213
|
return captured;
|
|
1188
1214
|
}
|
|
1189
|
-
const rendered = await renderObjectCapture(session, objectId);
|
|
1215
|
+
const rendered = await renderObjectCapture(session, objectId, maxValueLength);
|
|
1190
1216
|
if (rendered === void 0) {
|
|
1191
1217
|
return captured;
|
|
1192
1218
|
}
|
|
@@ -1194,10 +1220,11 @@ async function withSerializedObjectCapture(session, expression, evalResult, capt
|
|
|
1194
1220
|
if (normalized === void 0) {
|
|
1195
1221
|
return captured;
|
|
1196
1222
|
}
|
|
1197
|
-
const value = limitValueLength(normalized);
|
|
1223
|
+
const value = limitValueLength(normalized, maxValueLength);
|
|
1198
1224
|
return captured.type === void 0 ? { expression, value } : { expression, value, type: captured.type };
|
|
1199
1225
|
}
|
|
1200
1226
|
async function captureSnapshot(session, pause, options = {}) {
|
|
1227
|
+
const maxValueLength = resolveMaxValueLength(options.maxValueLength);
|
|
1201
1228
|
const top = pause.callFrames[0];
|
|
1202
1229
|
let topFrame;
|
|
1203
1230
|
let captures = [];
|
|
@@ -1209,7 +1236,7 @@ async function captureSnapshot(session, pause, options = {}) {
|
|
|
1209
1236
|
column: top.columnNumber + 1
|
|
1210
1237
|
};
|
|
1211
1238
|
if (options.includeScopes === true) {
|
|
1212
|
-
const scopes = await captureScopes(session, top);
|
|
1239
|
+
const scopes = await captureScopes(session, top, maxValueLength);
|
|
1213
1240
|
topFrame = { ...topFrame, scopes };
|
|
1214
1241
|
}
|
|
1215
1242
|
if (options.captures !== void 0 && options.captures.length > 0) {
|
|
@@ -1217,11 +1244,17 @@ async function captureSnapshot(session, pause, options = {}) {
|
|
|
1217
1244
|
options.captures.map(async (expression) => {
|
|
1218
1245
|
try {
|
|
1219
1246
|
const result = await evaluateOnFrame(session, top.callFrameId, expression);
|
|
1220
|
-
const captured = evalResultToCaptured(expression, result);
|
|
1221
|
-
return await withSerializedObjectCapture(
|
|
1247
|
+
const captured = evalResultToCaptured(expression, result, maxValueLength);
|
|
1248
|
+
return await withSerializedObjectCapture(
|
|
1249
|
+
session,
|
|
1250
|
+
expression,
|
|
1251
|
+
result,
|
|
1252
|
+
captured,
|
|
1253
|
+
maxValueLength
|
|
1254
|
+
);
|
|
1222
1255
|
} catch (err) {
|
|
1223
1256
|
const message = err instanceof Error ? err.message : String(err);
|
|
1224
|
-
return { expression, error: limitValueLength(message) };
|
|
1257
|
+
return { expression, error: limitValueLength(message, maxValueLength) };
|
|
1225
1258
|
}
|
|
1226
1259
|
})
|
|
1227
1260
|
);
|