@uipath/solution-sdk 1.196.0 → 1.197.0-preview.60
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/index.js +162 -1476
- package/dist/scripts/generate-sdk.js +2 -0
- package/dist/src/zip-utils.d.ts +17 -1
- package/package.json +33 -42
- package/dist/index.js.map +0 -159
- package/dist/scripts/generate-sdk.js.map +0 -10
package/dist/index.js
CHANGED
|
@@ -2155,6 +2155,12 @@ function singleton(ctorOrName) {
|
|
|
2155
2155
|
};
|
|
2156
2156
|
}
|
|
2157
2157
|
|
|
2158
|
+
// ../common/src/telemetry/global-telemetry-properties.ts
|
|
2159
|
+
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
2160
|
+
function getGlobalTelemetryProperties() {
|
|
2161
|
+
return telemetryPropsSlot.get();
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2158
2164
|
// ../common/src/sdk-user-agent.ts
|
|
2159
2165
|
var USER_AGENT_HEADER = "User-Agent";
|
|
2160
2166
|
var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
|
|
@@ -2178,8 +2184,8 @@ function appendUserAgentToken(value, userAgent) {
|
|
|
2178
2184
|
function getEffectiveUserAgent(userAgent) {
|
|
2179
2185
|
return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
|
|
2180
2186
|
}
|
|
2181
|
-
function
|
|
2182
|
-
return
|
|
2187
|
+
function getHeaderName(headers, headerName) {
|
|
2188
|
+
return Object.keys(headers).find((key) => key.toLowerCase() === headerName.toLowerCase());
|
|
2183
2189
|
}
|
|
2184
2190
|
function getSdkUserAgentToken(pkg) {
|
|
2185
2191
|
const packageName = pkg.name.replace(/^@uipath\//, "");
|
|
@@ -2187,59 +2193,31 @@ function getSdkUserAgentToken(pkg) {
|
|
|
2187
2193
|
}
|
|
2188
2194
|
function addSdkUserAgentHeader(headers, userAgent) {
|
|
2189
2195
|
const result = { ...headers ?? {} };
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
if (headerName) {
|
|
2193
|
-
result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
|
|
2194
|
-
} else {
|
|
2195
|
-
result[USER_AGENT_HEADER] = effectiveUserAgent;
|
|
2196
|
-
}
|
|
2196
|
+
const headerName = getHeaderName(result, USER_AGENT_HEADER);
|
|
2197
|
+
result[headerName ?? USER_AGENT_HEADER] = appendUserAgentToken(headerName ? result[headerName] : undefined, getEffectiveUserAgent(userAgent));
|
|
2197
2198
|
return result;
|
|
2198
2199
|
}
|
|
2199
|
-
function
|
|
2200
|
-
|
|
2201
|
-
if (isHeadersLike(headers)) {
|
|
2202
|
-
headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
|
|
2203
|
-
return headers;
|
|
2204
|
-
}
|
|
2205
|
-
if (Array.isArray(headers)) {
|
|
2206
|
-
const result = headers.map((entry) => {
|
|
2207
|
-
const [key, value] = entry;
|
|
2208
|
-
return [key, value];
|
|
2209
|
-
});
|
|
2210
|
-
const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
|
|
2211
|
-
if (headerIndex >= 0) {
|
|
2212
|
-
const [key, value] = result[headerIndex];
|
|
2213
|
-
result[headerIndex] = [
|
|
2214
|
-
key,
|
|
2215
|
-
appendUserAgentToken(value, effectiveUserAgent)
|
|
2216
|
-
];
|
|
2217
|
-
} else {
|
|
2218
|
-
result.push([USER_AGENT_HEADER, effectiveUserAgent]);
|
|
2219
|
-
}
|
|
2220
|
-
return result;
|
|
2221
|
-
}
|
|
2222
|
-
return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
|
|
2200
|
+
function asHeaderRecord(headers) {
|
|
2201
|
+
return typeof headers === "object" && headers !== null ? { ...headers } : {};
|
|
2223
2202
|
}
|
|
2224
|
-
function
|
|
2203
|
+
function withForwardedHeadersInitOverride(initOverrides, forward) {
|
|
2225
2204
|
return async (requestContext) => {
|
|
2226
|
-
const
|
|
2205
|
+
const initWithHeaders = {
|
|
2227
2206
|
...requestContext.init,
|
|
2228
|
-
headers:
|
|
2207
|
+
headers: forward(asHeaderRecord(requestContext.init.headers))
|
|
2229
2208
|
};
|
|
2230
2209
|
const override = typeof initOverrides === "function" ? await initOverrides({
|
|
2231
2210
|
...requestContext,
|
|
2232
|
-
init:
|
|
2211
|
+
init: initWithHeaders
|
|
2233
2212
|
}) : initOverrides;
|
|
2234
2213
|
return {
|
|
2235
2214
|
...override ?? {},
|
|
2236
|
-
headers:
|
|
2215
|
+
headers: forward(asHeaderRecord(override?.headers ?? initWithHeaders.headers))
|
|
2237
2216
|
};
|
|
2238
2217
|
};
|
|
2239
2218
|
}
|
|
2240
|
-
function
|
|
2219
|
+
function installRequestHeaderForwarding(BaseApiClass, patchKey, forward) {
|
|
2241
2220
|
const prototype = BaseApiClass.prototype;
|
|
2242
|
-
const patchKey = userAgentPatchKey(userAgent);
|
|
2243
2221
|
if (prototype[patchKey]) {
|
|
2244
2222
|
return;
|
|
2245
2223
|
}
|
|
@@ -2247,13 +2225,16 @@ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
|
2247
2225
|
throw new Error("Generated BaseAPI request function not found.");
|
|
2248
2226
|
}
|
|
2249
2227
|
const originalRequest = prototype.request;
|
|
2250
|
-
prototype.request = function
|
|
2251
|
-
return originalRequest.call(this, context,
|
|
2228
|
+
prototype.request = function requestWithForwardedHeaders(context, initOverrides) {
|
|
2229
|
+
return originalRequest.call(this, context, withForwardedHeadersInitOverride(initOverrides, forward));
|
|
2252
2230
|
};
|
|
2253
2231
|
Object.defineProperty(prototype, patchKey, {
|
|
2254
2232
|
value: true
|
|
2255
2233
|
});
|
|
2256
2234
|
}
|
|
2235
|
+
function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
2236
|
+
installRequestHeaderForwarding(BaseApiClass, userAgentPatchKey(userAgent), (headers) => addSdkUserAgentHeader(headers, userAgent));
|
|
2237
|
+
}
|
|
2257
2238
|
|
|
2258
2239
|
// generated/src/runtime.ts
|
|
2259
2240
|
var BASE_PATH = "https://alpha.uipath.com/uipattycyrhx/abizon_1/automationsolutions_".replace(/\/+$/, "");
|
|
@@ -2554,7 +2535,7 @@ class TextApiResponse {
|
|
|
2554
2535
|
var package_default = {
|
|
2555
2536
|
name: "@uipath/solution-sdk",
|
|
2556
2537
|
license: "MIT",
|
|
2557
|
-
version: "1.
|
|
2538
|
+
version: "1.197.0-preview.60",
|
|
2558
2539
|
repository: {
|
|
2559
2540
|
type: "git",
|
|
2560
2541
|
url: "https://github.com/UiPath/cli.git",
|
|
@@ -2585,7 +2566,7 @@ var package_default = {
|
|
|
2585
2566
|
],
|
|
2586
2567
|
private: false,
|
|
2587
2568
|
scripts: {
|
|
2588
|
-
build: "bun build ./src/index.ts --outdir dist --format esm --target node && bun build ./src/scripts/generate-sdk.ts --outdir dist/scripts --format esm --target node && tsc -p tsconfig.build.json --noCheck",
|
|
2569
|
+
build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && bun build ./src/scripts/generate-sdk.ts --outdir dist/scripts --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
2589
2570
|
generate: "bun run src/scripts/generate-sdk.ts",
|
|
2590
2571
|
lint: "biome check .",
|
|
2591
2572
|
test: "vitest run",
|
|
@@ -5542,6 +5523,7 @@ var CONSOLE_FALLBACK = {
|
|
|
5542
5523
|
writeLog: (str) => process.stdout.write(str),
|
|
5543
5524
|
capabilities: {
|
|
5544
5525
|
isInteractive: false,
|
|
5526
|
+
canReadInput: false,
|
|
5545
5527
|
supportsColor: false,
|
|
5546
5528
|
outputWidth: 80
|
|
5547
5529
|
}
|
|
@@ -10546,12 +10528,6 @@ class NodeContextStorage {
|
|
|
10546
10528
|
return this.storage.getStore();
|
|
10547
10529
|
}
|
|
10548
10530
|
}
|
|
10549
|
-
// ../common/src/telemetry/global-telemetry-properties.ts
|
|
10550
|
-
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
10551
|
-
function getGlobalTelemetryProperties() {
|
|
10552
|
-
return telemetryPropsSlot.get();
|
|
10553
|
-
}
|
|
10554
|
-
|
|
10555
10531
|
// ../common/src/telemetry/telemetry-service.ts
|
|
10556
10532
|
class TelemetryService {
|
|
10557
10533
|
telemetryProvider;
|
|
@@ -10741,6 +10717,29 @@ function isPlainRecord(value) {
|
|
|
10741
10717
|
const prototype = Object.getPrototypeOf(value);
|
|
10742
10718
|
return prototype === Object.prototype || prototype === null;
|
|
10743
10719
|
}
|
|
10720
|
+
function extractPagedRows(value) {
|
|
10721
|
+
if (Array.isArray(value) || !isPlainRecord(value))
|
|
10722
|
+
return null;
|
|
10723
|
+
const entries = Object.values(value);
|
|
10724
|
+
if (entries.length === 0)
|
|
10725
|
+
return null;
|
|
10726
|
+
let rows = null;
|
|
10727
|
+
let hasScalarSibling = false;
|
|
10728
|
+
for (const entry of entries) {
|
|
10729
|
+
if (Array.isArray(entry)) {
|
|
10730
|
+
if (rows !== null)
|
|
10731
|
+
return null;
|
|
10732
|
+
rows = entry;
|
|
10733
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
10734
|
+
return null;
|
|
10735
|
+
} else {
|
|
10736
|
+
hasScalarSibling = true;
|
|
10737
|
+
}
|
|
10738
|
+
}
|
|
10739
|
+
if (rows === null || !hasScalarSibling)
|
|
10740
|
+
return null;
|
|
10741
|
+
return rows;
|
|
10742
|
+
}
|
|
10744
10743
|
function toLowerCamelCaseKey(key) {
|
|
10745
10744
|
if (!key)
|
|
10746
10745
|
return key;
|
|
@@ -10805,7 +10804,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
10805
10804
|
break;
|
|
10806
10805
|
case "plain": {
|
|
10807
10806
|
if ("Data" in data && data.Data != null) {
|
|
10808
|
-
const
|
|
10807
|
+
const pagedRows = extractPagedRows(data.Data);
|
|
10808
|
+
const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
|
|
10809
10809
|
items.forEach((item) => {
|
|
10810
10810
|
const values = Object.values(item).map((v) => v ?? "").join("\t");
|
|
10811
10811
|
logFn(values);
|
|
@@ -10817,10 +10817,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
10817
10817
|
break;
|
|
10818
10818
|
}
|
|
10819
10819
|
default: {
|
|
10820
|
-
|
|
10820
|
+
const hasData = "Data" in data && data.Data != null;
|
|
10821
|
+
const pagedRows = hasData ? extractPagedRows(data.Data) : null;
|
|
10822
|
+
const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
|
|
10823
|
+
if (hasData && !(rows !== null && rows.length === 0)) {
|
|
10821
10824
|
const logValue = data.Log;
|
|
10822
|
-
if (
|
|
10823
|
-
printResizableTable(
|
|
10825
|
+
if (rows !== null) {
|
|
10826
|
+
printResizableTable(rows, logFn, logValue);
|
|
10824
10827
|
} else {
|
|
10825
10828
|
printVerticalTable(data.Data, logFn, logValue);
|
|
10826
10829
|
}
|
|
@@ -11008,6 +11011,44 @@ function defaultErrorCodeForResult(result) {
|
|
|
11008
11011
|
return "unknown_error";
|
|
11009
11012
|
}
|
|
11010
11013
|
}
|
|
11014
|
+
function parseHttpStatusFromMessage(message) {
|
|
11015
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
11016
|
+
if (!match)
|
|
11017
|
+
return;
|
|
11018
|
+
const status = Number(match[1]);
|
|
11019
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
11020
|
+
}
|
|
11021
|
+
function defaultErrorCodeForHttpStatus(status) {
|
|
11022
|
+
if (status === undefined)
|
|
11023
|
+
return;
|
|
11024
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
11025
|
+
return "invalid_argument";
|
|
11026
|
+
}
|
|
11027
|
+
if (status === 401)
|
|
11028
|
+
return "authentication_required";
|
|
11029
|
+
if (status === 403)
|
|
11030
|
+
return "permission_denied";
|
|
11031
|
+
if (status === 404)
|
|
11032
|
+
return "not_found";
|
|
11033
|
+
if (status === 405)
|
|
11034
|
+
return "method_not_allowed";
|
|
11035
|
+
if (status === 408)
|
|
11036
|
+
return "timeout";
|
|
11037
|
+
if (status === 429)
|
|
11038
|
+
return "rate_limited";
|
|
11039
|
+
if (status >= 500 && status < 600)
|
|
11040
|
+
return "server_error";
|
|
11041
|
+
return;
|
|
11042
|
+
}
|
|
11043
|
+
function defaultErrorCodeForFailure(data) {
|
|
11044
|
+
if (data.Result === RESULTS.Failure) {
|
|
11045
|
+
const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage(data.Message);
|
|
11046
|
+
const errorCode = defaultErrorCodeForHttpStatus(status);
|
|
11047
|
+
if (errorCode)
|
|
11048
|
+
return errorCode;
|
|
11049
|
+
}
|
|
11050
|
+
return defaultErrorCodeForResult(data.Result);
|
|
11051
|
+
}
|
|
11011
11052
|
function defaultRetryForErrorCode(errorCode) {
|
|
11012
11053
|
switch (errorCode) {
|
|
11013
11054
|
case "network_error":
|
|
@@ -11037,16 +11078,19 @@ var OutputFormatter;
|
|
|
11037
11078
|
OutputFormatter.success = success;
|
|
11038
11079
|
function error(data) {
|
|
11039
11080
|
data.Log ??= getLogFilePath() || undefined;
|
|
11040
|
-
data.ErrorCode ??=
|
|
11081
|
+
data.ErrorCode ??= defaultErrorCodeForFailure(data);
|
|
11041
11082
|
data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
|
|
11042
11083
|
process.exitCode = EXIT_CODES[data.Result] ?? 1;
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11084
|
+
const { SuppressTelemetry, ...envelope } = data;
|
|
11085
|
+
if (!SuppressTelemetry) {
|
|
11086
|
+
telemetry.trackEvent(CommonTelemetryEvents.Error, {
|
|
11087
|
+
result: data.Result,
|
|
11088
|
+
errorCode: data.ErrorCode,
|
|
11089
|
+
retry: data.Retry,
|
|
11090
|
+
message: data.Message
|
|
11091
|
+
});
|
|
11092
|
+
}
|
|
11093
|
+
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
11050
11094
|
}
|
|
11051
11095
|
OutputFormatter.error = error;
|
|
11052
11096
|
function emitList(code, items, opts) {
|
|
@@ -11328,1409 +11372,6 @@ var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
|
|
|
11328
11372
|
var DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
|
|
11329
11373
|
// ../common/src/interactivity-context.ts
|
|
11330
11374
|
var modeSlot = singleton("InteractivityMode");
|
|
11331
|
-
// ../../node_modules/jsonpath-plus/dist/index-node-esm.js
|
|
11332
|
-
import vm from "vm";
|
|
11333
|
-
|
|
11334
|
-
class Hooks {
|
|
11335
|
-
add(name, callback, first) {
|
|
11336
|
-
if (typeof arguments[0] != "string") {
|
|
11337
|
-
for (let name2 in arguments[0]) {
|
|
11338
|
-
this.add(name2, arguments[0][name2], arguments[1]);
|
|
11339
|
-
}
|
|
11340
|
-
} else {
|
|
11341
|
-
(Array.isArray(name) ? name : [name]).forEach(function(name2) {
|
|
11342
|
-
this[name2] = this[name2] || [];
|
|
11343
|
-
if (callback) {
|
|
11344
|
-
this[name2][first ? "unshift" : "push"](callback);
|
|
11345
|
-
}
|
|
11346
|
-
}, this);
|
|
11347
|
-
}
|
|
11348
|
-
}
|
|
11349
|
-
run(name, env) {
|
|
11350
|
-
this[name] = this[name] || [];
|
|
11351
|
-
this[name].forEach(function(callback) {
|
|
11352
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
11353
|
-
});
|
|
11354
|
-
}
|
|
11355
|
-
}
|
|
11356
|
-
|
|
11357
|
-
class Plugins {
|
|
11358
|
-
constructor(jsep) {
|
|
11359
|
-
this.jsep = jsep;
|
|
11360
|
-
this.registered = {};
|
|
11361
|
-
}
|
|
11362
|
-
register(...plugins) {
|
|
11363
|
-
plugins.forEach((plugin) => {
|
|
11364
|
-
if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
|
|
11365
|
-
throw new Error("Invalid JSEP plugin format");
|
|
11366
|
-
}
|
|
11367
|
-
if (this.registered[plugin.name]) {
|
|
11368
|
-
return;
|
|
11369
|
-
}
|
|
11370
|
-
plugin.init(this.jsep);
|
|
11371
|
-
this.registered[plugin.name] = plugin;
|
|
11372
|
-
});
|
|
11373
|
-
}
|
|
11374
|
-
}
|
|
11375
|
-
|
|
11376
|
-
class Jsep {
|
|
11377
|
-
static get version() {
|
|
11378
|
-
return "1.4.0";
|
|
11379
|
-
}
|
|
11380
|
-
static toString() {
|
|
11381
|
-
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
11382
|
-
}
|
|
11383
|
-
static addUnaryOp(op_name) {
|
|
11384
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
11385
|
-
Jsep.unary_ops[op_name] = 1;
|
|
11386
|
-
return Jsep;
|
|
11387
|
-
}
|
|
11388
|
-
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
11389
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
11390
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
11391
|
-
if (isRightAssociative) {
|
|
11392
|
-
Jsep.right_associative.add(op_name);
|
|
11393
|
-
} else {
|
|
11394
|
-
Jsep.right_associative.delete(op_name);
|
|
11395
|
-
}
|
|
11396
|
-
return Jsep;
|
|
11397
|
-
}
|
|
11398
|
-
static addIdentifierChar(char) {
|
|
11399
|
-
Jsep.additional_identifier_chars.add(char);
|
|
11400
|
-
return Jsep;
|
|
11401
|
-
}
|
|
11402
|
-
static addLiteral(literal_name, literal_value) {
|
|
11403
|
-
Jsep.literals[literal_name] = literal_value;
|
|
11404
|
-
return Jsep;
|
|
11405
|
-
}
|
|
11406
|
-
static removeUnaryOp(op_name) {
|
|
11407
|
-
delete Jsep.unary_ops[op_name];
|
|
11408
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
11409
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
11410
|
-
}
|
|
11411
|
-
return Jsep;
|
|
11412
|
-
}
|
|
11413
|
-
static removeAllUnaryOps() {
|
|
11414
|
-
Jsep.unary_ops = {};
|
|
11415
|
-
Jsep.max_unop_len = 0;
|
|
11416
|
-
return Jsep;
|
|
11417
|
-
}
|
|
11418
|
-
static removeIdentifierChar(char) {
|
|
11419
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
11420
|
-
return Jsep;
|
|
11421
|
-
}
|
|
11422
|
-
static removeBinaryOp(op_name) {
|
|
11423
|
-
delete Jsep.binary_ops[op_name];
|
|
11424
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
11425
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
11426
|
-
}
|
|
11427
|
-
Jsep.right_associative.delete(op_name);
|
|
11428
|
-
return Jsep;
|
|
11429
|
-
}
|
|
11430
|
-
static removeAllBinaryOps() {
|
|
11431
|
-
Jsep.binary_ops = {};
|
|
11432
|
-
Jsep.max_binop_len = 0;
|
|
11433
|
-
return Jsep;
|
|
11434
|
-
}
|
|
11435
|
-
static removeLiteral(literal_name) {
|
|
11436
|
-
delete Jsep.literals[literal_name];
|
|
11437
|
-
return Jsep;
|
|
11438
|
-
}
|
|
11439
|
-
static removeAllLiterals() {
|
|
11440
|
-
Jsep.literals = {};
|
|
11441
|
-
return Jsep;
|
|
11442
|
-
}
|
|
11443
|
-
get char() {
|
|
11444
|
-
return this.expr.charAt(this.index);
|
|
11445
|
-
}
|
|
11446
|
-
get code() {
|
|
11447
|
-
return this.expr.charCodeAt(this.index);
|
|
11448
|
-
}
|
|
11449
|
-
constructor(expr) {
|
|
11450
|
-
this.expr = expr;
|
|
11451
|
-
this.index = 0;
|
|
11452
|
-
}
|
|
11453
|
-
static parse(expr) {
|
|
11454
|
-
return new Jsep(expr).parse();
|
|
11455
|
-
}
|
|
11456
|
-
static getMaxKeyLen(obj) {
|
|
11457
|
-
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
11458
|
-
}
|
|
11459
|
-
static isDecimalDigit(ch) {
|
|
11460
|
-
return ch >= 48 && ch <= 57;
|
|
11461
|
-
}
|
|
11462
|
-
static binaryPrecedence(op_val) {
|
|
11463
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
11464
|
-
}
|
|
11465
|
-
static isIdentifierStart(ch) {
|
|
11466
|
-
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
|
|
11467
|
-
}
|
|
11468
|
-
static isIdentifierPart(ch) {
|
|
11469
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
11470
|
-
}
|
|
11471
|
-
throwError(message) {
|
|
11472
|
-
const error = new Error(message + " at character " + this.index);
|
|
11473
|
-
error.index = this.index;
|
|
11474
|
-
error.description = message;
|
|
11475
|
-
throw error;
|
|
11476
|
-
}
|
|
11477
|
-
runHook(name, node) {
|
|
11478
|
-
if (Jsep.hooks[name]) {
|
|
11479
|
-
const env = {
|
|
11480
|
-
context: this,
|
|
11481
|
-
node
|
|
11482
|
-
};
|
|
11483
|
-
Jsep.hooks.run(name, env);
|
|
11484
|
-
return env.node;
|
|
11485
|
-
}
|
|
11486
|
-
return node;
|
|
11487
|
-
}
|
|
11488
|
-
searchHook(name) {
|
|
11489
|
-
if (Jsep.hooks[name]) {
|
|
11490
|
-
const env = {
|
|
11491
|
-
context: this
|
|
11492
|
-
};
|
|
11493
|
-
Jsep.hooks[name].find(function(callback) {
|
|
11494
|
-
callback.call(env.context, env);
|
|
11495
|
-
return env.node;
|
|
11496
|
-
});
|
|
11497
|
-
return env.node;
|
|
11498
|
-
}
|
|
11499
|
-
}
|
|
11500
|
-
gobbleSpaces() {
|
|
11501
|
-
let ch = this.code;
|
|
11502
|
-
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
11503
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
11504
|
-
}
|
|
11505
|
-
this.runHook("gobble-spaces");
|
|
11506
|
-
}
|
|
11507
|
-
parse() {
|
|
11508
|
-
this.runHook("before-all");
|
|
11509
|
-
const nodes = this.gobbleExpressions();
|
|
11510
|
-
const node = nodes.length === 1 ? nodes[0] : {
|
|
11511
|
-
type: Jsep.COMPOUND,
|
|
11512
|
-
body: nodes
|
|
11513
|
-
};
|
|
11514
|
-
return this.runHook("after-all", node);
|
|
11515
|
-
}
|
|
11516
|
-
gobbleExpressions(untilICode) {
|
|
11517
|
-
let nodes = [], ch_i, node;
|
|
11518
|
-
while (this.index < this.expr.length) {
|
|
11519
|
-
ch_i = this.code;
|
|
11520
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
11521
|
-
this.index++;
|
|
11522
|
-
} else {
|
|
11523
|
-
if (node = this.gobbleExpression()) {
|
|
11524
|
-
nodes.push(node);
|
|
11525
|
-
} else if (this.index < this.expr.length) {
|
|
11526
|
-
if (ch_i === untilICode) {
|
|
11527
|
-
break;
|
|
11528
|
-
}
|
|
11529
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
11530
|
-
}
|
|
11531
|
-
}
|
|
11532
|
-
}
|
|
11533
|
-
return nodes;
|
|
11534
|
-
}
|
|
11535
|
-
gobbleExpression() {
|
|
11536
|
-
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
11537
|
-
this.gobbleSpaces();
|
|
11538
|
-
return this.runHook("after-expression", node);
|
|
11539
|
-
}
|
|
11540
|
-
gobbleBinaryOp() {
|
|
11541
|
-
this.gobbleSpaces();
|
|
11542
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
11543
|
-
let tc_len = to_check.length;
|
|
11544
|
-
while (tc_len > 0) {
|
|
11545
|
-
if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
11546
|
-
this.index += tc_len;
|
|
11547
|
-
return to_check;
|
|
11548
|
-
}
|
|
11549
|
-
to_check = to_check.substr(0, --tc_len);
|
|
11550
|
-
}
|
|
11551
|
-
return false;
|
|
11552
|
-
}
|
|
11553
|
-
gobbleBinaryExpression() {
|
|
11554
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
11555
|
-
left = this.gobbleToken();
|
|
11556
|
-
if (!left) {
|
|
11557
|
-
return left;
|
|
11558
|
-
}
|
|
11559
|
-
biop = this.gobbleBinaryOp();
|
|
11560
|
-
if (!biop) {
|
|
11561
|
-
return left;
|
|
11562
|
-
}
|
|
11563
|
-
biop_info = {
|
|
11564
|
-
value: biop,
|
|
11565
|
-
prec: Jsep.binaryPrecedence(biop),
|
|
11566
|
-
right_a: Jsep.right_associative.has(biop)
|
|
11567
|
-
};
|
|
11568
|
-
right = this.gobbleToken();
|
|
11569
|
-
if (!right) {
|
|
11570
|
-
this.throwError("Expected expression after " + biop);
|
|
11571
|
-
}
|
|
11572
|
-
stack = [left, biop_info, right];
|
|
11573
|
-
while (biop = this.gobbleBinaryOp()) {
|
|
11574
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
11575
|
-
if (prec === 0) {
|
|
11576
|
-
this.index -= biop.length;
|
|
11577
|
-
break;
|
|
11578
|
-
}
|
|
11579
|
-
biop_info = {
|
|
11580
|
-
value: biop,
|
|
11581
|
-
prec,
|
|
11582
|
-
right_a: Jsep.right_associative.has(biop)
|
|
11583
|
-
};
|
|
11584
|
-
cur_biop = biop;
|
|
11585
|
-
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
11586
|
-
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
11587
|
-
right = stack.pop();
|
|
11588
|
-
biop = stack.pop().value;
|
|
11589
|
-
left = stack.pop();
|
|
11590
|
-
node = {
|
|
11591
|
-
type: Jsep.BINARY_EXP,
|
|
11592
|
-
operator: biop,
|
|
11593
|
-
left,
|
|
11594
|
-
right
|
|
11595
|
-
};
|
|
11596
|
-
stack.push(node);
|
|
11597
|
-
}
|
|
11598
|
-
node = this.gobbleToken();
|
|
11599
|
-
if (!node) {
|
|
11600
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
11601
|
-
}
|
|
11602
|
-
stack.push(biop_info, node);
|
|
11603
|
-
}
|
|
11604
|
-
i = stack.length - 1;
|
|
11605
|
-
node = stack[i];
|
|
11606
|
-
while (i > 1) {
|
|
11607
|
-
node = {
|
|
11608
|
-
type: Jsep.BINARY_EXP,
|
|
11609
|
-
operator: stack[i - 1].value,
|
|
11610
|
-
left: stack[i - 2],
|
|
11611
|
-
right: node
|
|
11612
|
-
};
|
|
11613
|
-
i -= 2;
|
|
11614
|
-
}
|
|
11615
|
-
return node;
|
|
11616
|
-
}
|
|
11617
|
-
gobbleToken() {
|
|
11618
|
-
let ch, to_check, tc_len, node;
|
|
11619
|
-
this.gobbleSpaces();
|
|
11620
|
-
node = this.searchHook("gobble-token");
|
|
11621
|
-
if (node) {
|
|
11622
|
-
return this.runHook("after-token", node);
|
|
11623
|
-
}
|
|
11624
|
-
ch = this.code;
|
|
11625
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
11626
|
-
return this.gobbleNumericLiteral();
|
|
11627
|
-
}
|
|
11628
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
11629
|
-
node = this.gobbleStringLiteral();
|
|
11630
|
-
} else if (ch === Jsep.OBRACK_CODE) {
|
|
11631
|
-
node = this.gobbleArray();
|
|
11632
|
-
} else {
|
|
11633
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
11634
|
-
tc_len = to_check.length;
|
|
11635
|
-
while (tc_len > 0) {
|
|
11636
|
-
if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
11637
|
-
this.index += tc_len;
|
|
11638
|
-
const argument = this.gobbleToken();
|
|
11639
|
-
if (!argument) {
|
|
11640
|
-
this.throwError("missing unaryOp argument");
|
|
11641
|
-
}
|
|
11642
|
-
return this.runHook("after-token", {
|
|
11643
|
-
type: Jsep.UNARY_EXP,
|
|
11644
|
-
operator: to_check,
|
|
11645
|
-
argument,
|
|
11646
|
-
prefix: true
|
|
11647
|
-
});
|
|
11648
|
-
}
|
|
11649
|
-
to_check = to_check.substr(0, --tc_len);
|
|
11650
|
-
}
|
|
11651
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
11652
|
-
node = this.gobbleIdentifier();
|
|
11653
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
11654
|
-
node = {
|
|
11655
|
-
type: Jsep.LITERAL,
|
|
11656
|
-
value: Jsep.literals[node.name],
|
|
11657
|
-
raw: node.name
|
|
11658
|
-
};
|
|
11659
|
-
} else if (node.name === Jsep.this_str) {
|
|
11660
|
-
node = {
|
|
11661
|
-
type: Jsep.THIS_EXP
|
|
11662
|
-
};
|
|
11663
|
-
}
|
|
11664
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
11665
|
-
node = this.gobbleGroup();
|
|
11666
|
-
}
|
|
11667
|
-
}
|
|
11668
|
-
if (!node) {
|
|
11669
|
-
return this.runHook("after-token", false);
|
|
11670
|
-
}
|
|
11671
|
-
node = this.gobbleTokenProperty(node);
|
|
11672
|
-
return this.runHook("after-token", node);
|
|
11673
|
-
}
|
|
11674
|
-
gobbleTokenProperty(node) {
|
|
11675
|
-
this.gobbleSpaces();
|
|
11676
|
-
let ch = this.code;
|
|
11677
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
11678
|
-
let optional;
|
|
11679
|
-
if (ch === Jsep.QUMARK_CODE) {
|
|
11680
|
-
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
11681
|
-
break;
|
|
11682
|
-
}
|
|
11683
|
-
optional = true;
|
|
11684
|
-
this.index += 2;
|
|
11685
|
-
this.gobbleSpaces();
|
|
11686
|
-
ch = this.code;
|
|
11687
|
-
}
|
|
11688
|
-
this.index++;
|
|
11689
|
-
if (ch === Jsep.OBRACK_CODE) {
|
|
11690
|
-
node = {
|
|
11691
|
-
type: Jsep.MEMBER_EXP,
|
|
11692
|
-
computed: true,
|
|
11693
|
-
object: node,
|
|
11694
|
-
property: this.gobbleExpression()
|
|
11695
|
-
};
|
|
11696
|
-
if (!node.property) {
|
|
11697
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
11698
|
-
}
|
|
11699
|
-
this.gobbleSpaces();
|
|
11700
|
-
ch = this.code;
|
|
11701
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
11702
|
-
this.throwError("Unclosed [");
|
|
11703
|
-
}
|
|
11704
|
-
this.index++;
|
|
11705
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
11706
|
-
node = {
|
|
11707
|
-
type: Jsep.CALL_EXP,
|
|
11708
|
-
arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
11709
|
-
callee: node
|
|
11710
|
-
};
|
|
11711
|
-
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
11712
|
-
if (optional) {
|
|
11713
|
-
this.index--;
|
|
11714
|
-
}
|
|
11715
|
-
this.gobbleSpaces();
|
|
11716
|
-
node = {
|
|
11717
|
-
type: Jsep.MEMBER_EXP,
|
|
11718
|
-
computed: false,
|
|
11719
|
-
object: node,
|
|
11720
|
-
property: this.gobbleIdentifier()
|
|
11721
|
-
};
|
|
11722
|
-
}
|
|
11723
|
-
if (optional) {
|
|
11724
|
-
node.optional = true;
|
|
11725
|
-
}
|
|
11726
|
-
this.gobbleSpaces();
|
|
11727
|
-
ch = this.code;
|
|
11728
|
-
}
|
|
11729
|
-
return node;
|
|
11730
|
-
}
|
|
11731
|
-
gobbleNumericLiteral() {
|
|
11732
|
-
let number = "", ch, chCode;
|
|
11733
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
11734
|
-
number += this.expr.charAt(this.index++);
|
|
11735
|
-
}
|
|
11736
|
-
if (this.code === Jsep.PERIOD_CODE) {
|
|
11737
|
-
number += this.expr.charAt(this.index++);
|
|
11738
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
11739
|
-
number += this.expr.charAt(this.index++);
|
|
11740
|
-
}
|
|
11741
|
-
}
|
|
11742
|
-
ch = this.char;
|
|
11743
|
-
if (ch === "e" || ch === "E") {
|
|
11744
|
-
number += this.expr.charAt(this.index++);
|
|
11745
|
-
ch = this.char;
|
|
11746
|
-
if (ch === "+" || ch === "-") {
|
|
11747
|
-
number += this.expr.charAt(this.index++);
|
|
11748
|
-
}
|
|
11749
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
11750
|
-
number += this.expr.charAt(this.index++);
|
|
11751
|
-
}
|
|
11752
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
11753
|
-
this.throwError("Expected exponent (" + number + this.char + ")");
|
|
11754
|
-
}
|
|
11755
|
-
}
|
|
11756
|
-
chCode = this.code;
|
|
11757
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
11758
|
-
this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
|
|
11759
|
-
} else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
11760
|
-
this.throwError("Unexpected period");
|
|
11761
|
-
}
|
|
11762
|
-
return {
|
|
11763
|
-
type: Jsep.LITERAL,
|
|
11764
|
-
value: parseFloat(number),
|
|
11765
|
-
raw: number
|
|
11766
|
-
};
|
|
11767
|
-
}
|
|
11768
|
-
gobbleStringLiteral() {
|
|
11769
|
-
let str = "";
|
|
11770
|
-
const startIndex = this.index;
|
|
11771
|
-
const quote = this.expr.charAt(this.index++);
|
|
11772
|
-
let closed = false;
|
|
11773
|
-
while (this.index < this.expr.length) {
|
|
11774
|
-
let ch = this.expr.charAt(this.index++);
|
|
11775
|
-
if (ch === quote) {
|
|
11776
|
-
closed = true;
|
|
11777
|
-
break;
|
|
11778
|
-
} else if (ch === "\\") {
|
|
11779
|
-
ch = this.expr.charAt(this.index++);
|
|
11780
|
-
switch (ch) {
|
|
11781
|
-
case "n":
|
|
11782
|
-
str += `
|
|
11783
|
-
`;
|
|
11784
|
-
break;
|
|
11785
|
-
case "r":
|
|
11786
|
-
str += "\r";
|
|
11787
|
-
break;
|
|
11788
|
-
case "t":
|
|
11789
|
-
str += "\t";
|
|
11790
|
-
break;
|
|
11791
|
-
case "b":
|
|
11792
|
-
str += "\b";
|
|
11793
|
-
break;
|
|
11794
|
-
case "f":
|
|
11795
|
-
str += "\f";
|
|
11796
|
-
break;
|
|
11797
|
-
case "v":
|
|
11798
|
-
str += "\v";
|
|
11799
|
-
break;
|
|
11800
|
-
default:
|
|
11801
|
-
str += ch;
|
|
11802
|
-
}
|
|
11803
|
-
} else {
|
|
11804
|
-
str += ch;
|
|
11805
|
-
}
|
|
11806
|
-
}
|
|
11807
|
-
if (!closed) {
|
|
11808
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
11809
|
-
}
|
|
11810
|
-
return {
|
|
11811
|
-
type: Jsep.LITERAL,
|
|
11812
|
-
value: str,
|
|
11813
|
-
raw: this.expr.substring(startIndex, this.index)
|
|
11814
|
-
};
|
|
11815
|
-
}
|
|
11816
|
-
gobbleIdentifier() {
|
|
11817
|
-
let ch = this.code, start = this.index;
|
|
11818
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
11819
|
-
this.index++;
|
|
11820
|
-
} else {
|
|
11821
|
-
this.throwError("Unexpected " + this.char);
|
|
11822
|
-
}
|
|
11823
|
-
while (this.index < this.expr.length) {
|
|
11824
|
-
ch = this.code;
|
|
11825
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
11826
|
-
this.index++;
|
|
11827
|
-
} else {
|
|
11828
|
-
break;
|
|
11829
|
-
}
|
|
11830
|
-
}
|
|
11831
|
-
return {
|
|
11832
|
-
type: Jsep.IDENTIFIER,
|
|
11833
|
-
name: this.expr.slice(start, this.index)
|
|
11834
|
-
};
|
|
11835
|
-
}
|
|
11836
|
-
gobbleArguments(termination) {
|
|
11837
|
-
const args = [];
|
|
11838
|
-
let closed = false;
|
|
11839
|
-
let separator_count = 0;
|
|
11840
|
-
while (this.index < this.expr.length) {
|
|
11841
|
-
this.gobbleSpaces();
|
|
11842
|
-
let ch_i = this.code;
|
|
11843
|
-
if (ch_i === termination) {
|
|
11844
|
-
closed = true;
|
|
11845
|
-
this.index++;
|
|
11846
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
11847
|
-
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
11848
|
-
}
|
|
11849
|
-
break;
|
|
11850
|
-
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
11851
|
-
this.index++;
|
|
11852
|
-
separator_count++;
|
|
11853
|
-
if (separator_count !== args.length) {
|
|
11854
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
11855
|
-
this.throwError("Unexpected token ,");
|
|
11856
|
-
} else if (termination === Jsep.CBRACK_CODE) {
|
|
11857
|
-
for (let arg = args.length;arg < separator_count; arg++) {
|
|
11858
|
-
args.push(null);
|
|
11859
|
-
}
|
|
11860
|
-
}
|
|
11861
|
-
}
|
|
11862
|
-
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
11863
|
-
this.throwError("Expected comma");
|
|
11864
|
-
} else {
|
|
11865
|
-
const node = this.gobbleExpression();
|
|
11866
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
11867
|
-
this.throwError("Expected comma");
|
|
11868
|
-
}
|
|
11869
|
-
args.push(node);
|
|
11870
|
-
}
|
|
11871
|
-
}
|
|
11872
|
-
if (!closed) {
|
|
11873
|
-
this.throwError("Expected " + String.fromCharCode(termination));
|
|
11874
|
-
}
|
|
11875
|
-
return args;
|
|
11876
|
-
}
|
|
11877
|
-
gobbleGroup() {
|
|
11878
|
-
this.index++;
|
|
11879
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
11880
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
11881
|
-
this.index++;
|
|
11882
|
-
if (nodes.length === 1) {
|
|
11883
|
-
return nodes[0];
|
|
11884
|
-
} else if (!nodes.length) {
|
|
11885
|
-
return false;
|
|
11886
|
-
} else {
|
|
11887
|
-
return {
|
|
11888
|
-
type: Jsep.SEQUENCE_EXP,
|
|
11889
|
-
expressions: nodes
|
|
11890
|
-
};
|
|
11891
|
-
}
|
|
11892
|
-
} else {
|
|
11893
|
-
this.throwError("Unclosed (");
|
|
11894
|
-
}
|
|
11895
|
-
}
|
|
11896
|
-
gobbleArray() {
|
|
11897
|
-
this.index++;
|
|
11898
|
-
return {
|
|
11899
|
-
type: Jsep.ARRAY_EXP,
|
|
11900
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
11901
|
-
};
|
|
11902
|
-
}
|
|
11903
|
-
}
|
|
11904
|
-
var hooks = new Hooks;
|
|
11905
|
-
Object.assign(Jsep, {
|
|
11906
|
-
hooks,
|
|
11907
|
-
plugins: new Plugins(Jsep),
|
|
11908
|
-
COMPOUND: "Compound",
|
|
11909
|
-
SEQUENCE_EXP: "SequenceExpression",
|
|
11910
|
-
IDENTIFIER: "Identifier",
|
|
11911
|
-
MEMBER_EXP: "MemberExpression",
|
|
11912
|
-
LITERAL: "Literal",
|
|
11913
|
-
THIS_EXP: "ThisExpression",
|
|
11914
|
-
CALL_EXP: "CallExpression",
|
|
11915
|
-
UNARY_EXP: "UnaryExpression",
|
|
11916
|
-
BINARY_EXP: "BinaryExpression",
|
|
11917
|
-
ARRAY_EXP: "ArrayExpression",
|
|
11918
|
-
TAB_CODE: 9,
|
|
11919
|
-
LF_CODE: 10,
|
|
11920
|
-
CR_CODE: 13,
|
|
11921
|
-
SPACE_CODE: 32,
|
|
11922
|
-
PERIOD_CODE: 46,
|
|
11923
|
-
COMMA_CODE: 44,
|
|
11924
|
-
SQUOTE_CODE: 39,
|
|
11925
|
-
DQUOTE_CODE: 34,
|
|
11926
|
-
OPAREN_CODE: 40,
|
|
11927
|
-
CPAREN_CODE: 41,
|
|
11928
|
-
OBRACK_CODE: 91,
|
|
11929
|
-
CBRACK_CODE: 93,
|
|
11930
|
-
QUMARK_CODE: 63,
|
|
11931
|
-
SEMCOL_CODE: 59,
|
|
11932
|
-
COLON_CODE: 58,
|
|
11933
|
-
unary_ops: {
|
|
11934
|
-
"-": 1,
|
|
11935
|
-
"!": 1,
|
|
11936
|
-
"~": 1,
|
|
11937
|
-
"+": 1
|
|
11938
|
-
},
|
|
11939
|
-
binary_ops: {
|
|
11940
|
-
"||": 1,
|
|
11941
|
-
"??": 1,
|
|
11942
|
-
"&&": 2,
|
|
11943
|
-
"|": 3,
|
|
11944
|
-
"^": 4,
|
|
11945
|
-
"&": 5,
|
|
11946
|
-
"==": 6,
|
|
11947
|
-
"!=": 6,
|
|
11948
|
-
"===": 6,
|
|
11949
|
-
"!==": 6,
|
|
11950
|
-
"<": 7,
|
|
11951
|
-
">": 7,
|
|
11952
|
-
"<=": 7,
|
|
11953
|
-
">=": 7,
|
|
11954
|
-
"<<": 8,
|
|
11955
|
-
">>": 8,
|
|
11956
|
-
">>>": 8,
|
|
11957
|
-
"+": 9,
|
|
11958
|
-
"-": 9,
|
|
11959
|
-
"*": 10,
|
|
11960
|
-
"/": 10,
|
|
11961
|
-
"%": 10,
|
|
11962
|
-
"**": 11
|
|
11963
|
-
},
|
|
11964
|
-
right_associative: new Set(["**"]),
|
|
11965
|
-
additional_identifier_chars: new Set(["$", "_"]),
|
|
11966
|
-
literals: {
|
|
11967
|
-
true: true,
|
|
11968
|
-
false: false,
|
|
11969
|
-
null: null
|
|
11970
|
-
},
|
|
11971
|
-
this_str: "this"
|
|
11972
|
-
});
|
|
11973
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
11974
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
11975
|
-
var jsep = (expr) => new Jsep(expr).parse();
|
|
11976
|
-
var stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
11977
|
-
});
|
|
11978
|
-
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
|
|
11979
|
-
jsep[m] = Jsep[m];
|
|
11980
|
-
});
|
|
11981
|
-
jsep.Jsep = Jsep;
|
|
11982
|
-
var CONDITIONAL_EXP = "ConditionalExpression";
|
|
11983
|
-
var ternary = {
|
|
11984
|
-
name: "ternary",
|
|
11985
|
-
init(jsep2) {
|
|
11986
|
-
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
11987
|
-
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
11988
|
-
this.index++;
|
|
11989
|
-
const test = env.node;
|
|
11990
|
-
const consequent = this.gobbleExpression();
|
|
11991
|
-
if (!consequent) {
|
|
11992
|
-
this.throwError("Expected expression");
|
|
11993
|
-
}
|
|
11994
|
-
this.gobbleSpaces();
|
|
11995
|
-
if (this.code === jsep2.COLON_CODE) {
|
|
11996
|
-
this.index++;
|
|
11997
|
-
const alternate = this.gobbleExpression();
|
|
11998
|
-
if (!alternate) {
|
|
11999
|
-
this.throwError("Expected expression");
|
|
12000
|
-
}
|
|
12001
|
-
env.node = {
|
|
12002
|
-
type: CONDITIONAL_EXP,
|
|
12003
|
-
test,
|
|
12004
|
-
consequent,
|
|
12005
|
-
alternate
|
|
12006
|
-
};
|
|
12007
|
-
if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
|
|
12008
|
-
let newTest = test;
|
|
12009
|
-
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
12010
|
-
newTest = newTest.right;
|
|
12011
|
-
}
|
|
12012
|
-
env.node.test = newTest.right;
|
|
12013
|
-
newTest.right = env.node;
|
|
12014
|
-
env.node = test;
|
|
12015
|
-
}
|
|
12016
|
-
} else {
|
|
12017
|
-
this.throwError("Expected :");
|
|
12018
|
-
}
|
|
12019
|
-
}
|
|
12020
|
-
});
|
|
12021
|
-
}
|
|
12022
|
-
};
|
|
12023
|
-
jsep.plugins.register(ternary);
|
|
12024
|
-
var FSLASH_CODE = 47;
|
|
12025
|
-
var BSLASH_CODE = 92;
|
|
12026
|
-
var index = {
|
|
12027
|
-
name: "regex",
|
|
12028
|
-
init(jsep2) {
|
|
12029
|
-
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
12030
|
-
if (this.code === FSLASH_CODE) {
|
|
12031
|
-
const patternIndex = ++this.index;
|
|
12032
|
-
let inCharSet = false;
|
|
12033
|
-
while (this.index < this.expr.length) {
|
|
12034
|
-
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
12035
|
-
const pattern = this.expr.slice(patternIndex, this.index);
|
|
12036
|
-
let flags = "";
|
|
12037
|
-
while (++this.index < this.expr.length) {
|
|
12038
|
-
const code = this.code;
|
|
12039
|
-
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
12040
|
-
flags += this.char;
|
|
12041
|
-
} else {
|
|
12042
|
-
break;
|
|
12043
|
-
}
|
|
12044
|
-
}
|
|
12045
|
-
let value;
|
|
12046
|
-
try {
|
|
12047
|
-
value = new RegExp(pattern, flags);
|
|
12048
|
-
} catch (e) {
|
|
12049
|
-
this.throwError(e.message);
|
|
12050
|
-
}
|
|
12051
|
-
env.node = {
|
|
12052
|
-
type: jsep2.LITERAL,
|
|
12053
|
-
value,
|
|
12054
|
-
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
12055
|
-
};
|
|
12056
|
-
env.node = this.gobbleTokenProperty(env.node);
|
|
12057
|
-
return env.node;
|
|
12058
|
-
}
|
|
12059
|
-
if (this.code === jsep2.OBRACK_CODE) {
|
|
12060
|
-
inCharSet = true;
|
|
12061
|
-
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
12062
|
-
inCharSet = false;
|
|
12063
|
-
}
|
|
12064
|
-
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
12065
|
-
}
|
|
12066
|
-
this.throwError("Unclosed Regex");
|
|
12067
|
-
}
|
|
12068
|
-
});
|
|
12069
|
-
}
|
|
12070
|
-
};
|
|
12071
|
-
var PLUS_CODE = 43;
|
|
12072
|
-
var MINUS_CODE = 45;
|
|
12073
|
-
var plugin = {
|
|
12074
|
-
name: "assignment",
|
|
12075
|
-
assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
12076
|
-
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
12077
|
-
assignmentPrecedence: 0.9,
|
|
12078
|
-
init(jsep2) {
|
|
12079
|
-
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
12080
|
-
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
12081
|
-
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
12082
|
-
const code = this.code;
|
|
12083
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
12084
|
-
this.index += 2;
|
|
12085
|
-
env.node = {
|
|
12086
|
-
type: "UpdateExpression",
|
|
12087
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
12088
|
-
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
12089
|
-
prefix: true
|
|
12090
|
-
};
|
|
12091
|
-
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
12092
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
12093
|
-
}
|
|
12094
|
-
}
|
|
12095
|
-
});
|
|
12096
|
-
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
12097
|
-
if (env.node) {
|
|
12098
|
-
const code = this.code;
|
|
12099
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
12100
|
-
if (!updateNodeTypes.includes(env.node.type)) {
|
|
12101
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
12102
|
-
}
|
|
12103
|
-
this.index += 2;
|
|
12104
|
-
env.node = {
|
|
12105
|
-
type: "UpdateExpression",
|
|
12106
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
12107
|
-
argument: env.node,
|
|
12108
|
-
prefix: false
|
|
12109
|
-
};
|
|
12110
|
-
}
|
|
12111
|
-
}
|
|
12112
|
-
});
|
|
12113
|
-
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
12114
|
-
if (env.node) {
|
|
12115
|
-
updateBinariesToAssignments(env.node);
|
|
12116
|
-
}
|
|
12117
|
-
});
|
|
12118
|
-
function updateBinariesToAssignments(node) {
|
|
12119
|
-
if (plugin.assignmentOperators.has(node.operator)) {
|
|
12120
|
-
node.type = "AssignmentExpression";
|
|
12121
|
-
updateBinariesToAssignments(node.left);
|
|
12122
|
-
updateBinariesToAssignments(node.right);
|
|
12123
|
-
} else if (!node.operator) {
|
|
12124
|
-
Object.values(node).forEach((val) => {
|
|
12125
|
-
if (val && typeof val === "object") {
|
|
12126
|
-
updateBinariesToAssignments(val);
|
|
12127
|
-
}
|
|
12128
|
-
});
|
|
12129
|
-
}
|
|
12130
|
-
}
|
|
12131
|
-
}
|
|
12132
|
-
};
|
|
12133
|
-
jsep.plugins.register(index, plugin);
|
|
12134
|
-
jsep.addUnaryOp("typeof");
|
|
12135
|
-
jsep.addUnaryOp("void");
|
|
12136
|
-
jsep.addLiteral("null", null);
|
|
12137
|
-
jsep.addLiteral("undefined", undefined);
|
|
12138
|
-
var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
12139
|
-
var SafeEval = {
|
|
12140
|
-
evalAst(ast, subs) {
|
|
12141
|
-
switch (ast.type) {
|
|
12142
|
-
case "BinaryExpression":
|
|
12143
|
-
case "LogicalExpression":
|
|
12144
|
-
return SafeEval.evalBinaryExpression(ast, subs);
|
|
12145
|
-
case "Compound":
|
|
12146
|
-
return SafeEval.evalCompound(ast, subs);
|
|
12147
|
-
case "ConditionalExpression":
|
|
12148
|
-
return SafeEval.evalConditionalExpression(ast, subs);
|
|
12149
|
-
case "Identifier":
|
|
12150
|
-
return SafeEval.evalIdentifier(ast, subs);
|
|
12151
|
-
case "Literal":
|
|
12152
|
-
return SafeEval.evalLiteral(ast, subs);
|
|
12153
|
-
case "MemberExpression":
|
|
12154
|
-
return SafeEval.evalMemberExpression(ast, subs);
|
|
12155
|
-
case "UnaryExpression":
|
|
12156
|
-
return SafeEval.evalUnaryExpression(ast, subs);
|
|
12157
|
-
case "ArrayExpression":
|
|
12158
|
-
return SafeEval.evalArrayExpression(ast, subs);
|
|
12159
|
-
case "CallExpression":
|
|
12160
|
-
return SafeEval.evalCallExpression(ast, subs);
|
|
12161
|
-
case "AssignmentExpression":
|
|
12162
|
-
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
12163
|
-
default:
|
|
12164
|
-
throw SyntaxError("Unexpected expression", ast);
|
|
12165
|
-
}
|
|
12166
|
-
},
|
|
12167
|
-
evalBinaryExpression(ast, subs) {
|
|
12168
|
-
const result = {
|
|
12169
|
-
"||": (a, b) => a || b(),
|
|
12170
|
-
"&&": (a, b) => a && b(),
|
|
12171
|
-
"|": (a, b) => a | b(),
|
|
12172
|
-
"^": (a, b) => a ^ b(),
|
|
12173
|
-
"&": (a, b) => a & b(),
|
|
12174
|
-
"==": (a, b) => a == b(),
|
|
12175
|
-
"!=": (a, b) => a != b(),
|
|
12176
|
-
"===": (a, b) => a === b(),
|
|
12177
|
-
"!==": (a, b) => a !== b(),
|
|
12178
|
-
"<": (a, b) => a < b(),
|
|
12179
|
-
">": (a, b) => a > b(),
|
|
12180
|
-
"<=": (a, b) => a <= b(),
|
|
12181
|
-
">=": (a, b) => a >= b(),
|
|
12182
|
-
"<<": (a, b) => a << b(),
|
|
12183
|
-
">>": (a, b) => a >> b(),
|
|
12184
|
-
">>>": (a, b) => a >>> b(),
|
|
12185
|
-
"+": (a, b) => a + b(),
|
|
12186
|
-
"-": (a, b) => a - b(),
|
|
12187
|
-
"*": (a, b) => a * b(),
|
|
12188
|
-
"/": (a, b) => a / b(),
|
|
12189
|
-
"%": (a, b) => a % b()
|
|
12190
|
-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
12191
|
-
return result;
|
|
12192
|
-
},
|
|
12193
|
-
evalCompound(ast, subs) {
|
|
12194
|
-
let last;
|
|
12195
|
-
for (let i = 0;i < ast.body.length; i++) {
|
|
12196
|
-
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
12197
|
-
i += 1;
|
|
12198
|
-
}
|
|
12199
|
-
const expr = ast.body[i];
|
|
12200
|
-
last = SafeEval.evalAst(expr, subs);
|
|
12201
|
-
}
|
|
12202
|
-
return last;
|
|
12203
|
-
},
|
|
12204
|
-
evalConditionalExpression(ast, subs) {
|
|
12205
|
-
if (SafeEval.evalAst(ast.test, subs)) {
|
|
12206
|
-
return SafeEval.evalAst(ast.consequent, subs);
|
|
12207
|
-
}
|
|
12208
|
-
return SafeEval.evalAst(ast.alternate, subs);
|
|
12209
|
-
},
|
|
12210
|
-
evalIdentifier(ast, subs) {
|
|
12211
|
-
if (Object.hasOwn(subs, ast.name)) {
|
|
12212
|
-
return subs[ast.name];
|
|
12213
|
-
}
|
|
12214
|
-
throw ReferenceError(`${ast.name} is not defined`);
|
|
12215
|
-
},
|
|
12216
|
-
evalLiteral(ast) {
|
|
12217
|
-
return ast.value;
|
|
12218
|
-
},
|
|
12219
|
-
evalMemberExpression(ast, subs) {
|
|
12220
|
-
const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
|
|
12221
|
-
const obj = SafeEval.evalAst(ast.object, subs);
|
|
12222
|
-
if (obj === undefined || obj === null) {
|
|
12223
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
12224
|
-
}
|
|
12225
|
-
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
12226
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
12227
|
-
}
|
|
12228
|
-
const result = obj[prop];
|
|
12229
|
-
if (typeof result === "function") {
|
|
12230
|
-
return result.bind(obj);
|
|
12231
|
-
}
|
|
12232
|
-
return result;
|
|
12233
|
-
},
|
|
12234
|
-
evalUnaryExpression(ast, subs) {
|
|
12235
|
-
const result = {
|
|
12236
|
-
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
12237
|
-
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
12238
|
-
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
12239
|
-
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
12240
|
-
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
12241
|
-
void: (a) => void SafeEval.evalAst(a, subs)
|
|
12242
|
-
}[ast.operator](ast.argument);
|
|
12243
|
-
return result;
|
|
12244
|
-
},
|
|
12245
|
-
evalArrayExpression(ast, subs) {
|
|
12246
|
-
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
12247
|
-
},
|
|
12248
|
-
evalCallExpression(ast, subs) {
|
|
12249
|
-
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
12250
|
-
const func = SafeEval.evalAst(ast.callee, subs);
|
|
12251
|
-
if (func === Function) {
|
|
12252
|
-
throw new Error("Function constructor is disabled");
|
|
12253
|
-
}
|
|
12254
|
-
return func(...args);
|
|
12255
|
-
},
|
|
12256
|
-
evalAssignmentExpression(ast, subs) {
|
|
12257
|
-
if (ast.left.type !== "Identifier") {
|
|
12258
|
-
throw SyntaxError("Invalid left-hand side in assignment");
|
|
12259
|
-
}
|
|
12260
|
-
const id = ast.left.name;
|
|
12261
|
-
const value = SafeEval.evalAst(ast.right, subs);
|
|
12262
|
-
subs[id] = value;
|
|
12263
|
-
return subs[id];
|
|
12264
|
-
}
|
|
12265
|
-
};
|
|
12266
|
-
|
|
12267
|
-
class SafeScript {
|
|
12268
|
-
constructor(expr) {
|
|
12269
|
-
this.code = expr;
|
|
12270
|
-
this.ast = jsep(this.code);
|
|
12271
|
-
}
|
|
12272
|
-
runInNewContext(context) {
|
|
12273
|
-
const keyMap = Object.assign(Object.create(null), context);
|
|
12274
|
-
return SafeEval.evalAst(this.ast, keyMap);
|
|
12275
|
-
}
|
|
12276
|
-
}
|
|
12277
|
-
function push(arr, item) {
|
|
12278
|
-
arr = arr.slice();
|
|
12279
|
-
arr.push(item);
|
|
12280
|
-
return arr;
|
|
12281
|
-
}
|
|
12282
|
-
function unshift(item, arr) {
|
|
12283
|
-
arr = arr.slice();
|
|
12284
|
-
arr.unshift(item);
|
|
12285
|
-
return arr;
|
|
12286
|
-
}
|
|
12287
|
-
|
|
12288
|
-
class NewError extends Error {
|
|
12289
|
-
constructor(value) {
|
|
12290
|
-
super('JSONPath should not be called with "new" (it prevents return ' + "of (unwrapped) scalar values)");
|
|
12291
|
-
this.avoidNew = true;
|
|
12292
|
-
this.value = value;
|
|
12293
|
-
this.name = "NewError";
|
|
12294
|
-
}
|
|
12295
|
-
}
|
|
12296
|
-
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
12297
|
-
if (!(this instanceof JSONPath)) {
|
|
12298
|
-
try {
|
|
12299
|
-
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
12300
|
-
} catch (e) {
|
|
12301
|
-
if (!e.avoidNew) {
|
|
12302
|
-
throw e;
|
|
12303
|
-
}
|
|
12304
|
-
return e.value;
|
|
12305
|
-
}
|
|
12306
|
-
}
|
|
12307
|
-
if (typeof opts === "string") {
|
|
12308
|
-
otherTypeCallback = callback;
|
|
12309
|
-
callback = obj;
|
|
12310
|
-
obj = expr;
|
|
12311
|
-
expr = opts;
|
|
12312
|
-
opts = null;
|
|
12313
|
-
}
|
|
12314
|
-
const optObj = opts && typeof opts === "object";
|
|
12315
|
-
opts = opts || {};
|
|
12316
|
-
this.json = opts.json || obj;
|
|
12317
|
-
this.path = opts.path || expr;
|
|
12318
|
-
this.resultType = opts.resultType || "value";
|
|
12319
|
-
this.flatten = opts.flatten || false;
|
|
12320
|
-
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
12321
|
-
this.sandbox = opts.sandbox || {};
|
|
12322
|
-
this.eval = opts.eval === undefined ? "safe" : opts.eval;
|
|
12323
|
-
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
12324
|
-
this.parent = opts.parent || null;
|
|
12325
|
-
this.parentProperty = opts.parentProperty || null;
|
|
12326
|
-
this.callback = opts.callback || callback || null;
|
|
12327
|
-
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
12328
|
-
throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
|
|
12329
|
-
};
|
|
12330
|
-
if (opts.autostart !== false) {
|
|
12331
|
-
const args = {
|
|
12332
|
-
path: optObj ? opts.path : expr
|
|
12333
|
-
};
|
|
12334
|
-
if (!optObj) {
|
|
12335
|
-
args.json = obj;
|
|
12336
|
-
} else if ("json" in opts) {
|
|
12337
|
-
args.json = opts.json;
|
|
12338
|
-
}
|
|
12339
|
-
const ret = this.evaluate(args);
|
|
12340
|
-
if (!ret || typeof ret !== "object") {
|
|
12341
|
-
throw new NewError(ret);
|
|
12342
|
-
}
|
|
12343
|
-
return ret;
|
|
12344
|
-
}
|
|
12345
|
-
}
|
|
12346
|
-
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
12347
|
-
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
12348
|
-
let {
|
|
12349
|
-
flatten,
|
|
12350
|
-
wrap
|
|
12351
|
-
} = this;
|
|
12352
|
-
this.currResultType = this.resultType;
|
|
12353
|
-
this.currEval = this.eval;
|
|
12354
|
-
this.currSandbox = this.sandbox;
|
|
12355
|
-
callback = callback || this.callback;
|
|
12356
|
-
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
12357
|
-
json = json || this.json;
|
|
12358
|
-
expr = expr || this.path;
|
|
12359
|
-
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
12360
|
-
if (!expr.path && expr.path !== "") {
|
|
12361
|
-
throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
12362
|
-
}
|
|
12363
|
-
if (!Object.hasOwn(expr, "json")) {
|
|
12364
|
-
throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
12365
|
-
}
|
|
12366
|
-
({
|
|
12367
|
-
json
|
|
12368
|
-
} = expr);
|
|
12369
|
-
flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
|
|
12370
|
-
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
12371
|
-
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
12372
|
-
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
12373
|
-
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
12374
|
-
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
12375
|
-
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
12376
|
-
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
12377
|
-
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
12378
|
-
expr = expr.path;
|
|
12379
|
-
}
|
|
12380
|
-
currParent = currParent || null;
|
|
12381
|
-
currParentProperty = currParentProperty || null;
|
|
12382
|
-
if (Array.isArray(expr)) {
|
|
12383
|
-
expr = JSONPath.toPathString(expr);
|
|
12384
|
-
}
|
|
12385
|
-
if (!expr && expr !== "" || !json) {
|
|
12386
|
-
return;
|
|
12387
|
-
}
|
|
12388
|
-
const exprList = JSONPath.toPathArray(expr);
|
|
12389
|
-
if (exprList[0] === "$" && exprList.length > 1) {
|
|
12390
|
-
exprList.shift();
|
|
12391
|
-
}
|
|
12392
|
-
this._hasParentSelector = null;
|
|
12393
|
-
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea) {
|
|
12394
|
-
return ea && !ea.isParentSelector;
|
|
12395
|
-
});
|
|
12396
|
-
if (!result.length) {
|
|
12397
|
-
return wrap ? [] : undefined;
|
|
12398
|
-
}
|
|
12399
|
-
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
12400
|
-
return this._getPreferredOutput(result[0]);
|
|
12401
|
-
}
|
|
12402
|
-
return result.reduce((rslt, ea) => {
|
|
12403
|
-
const valOrPath = this._getPreferredOutput(ea);
|
|
12404
|
-
if (flatten && Array.isArray(valOrPath)) {
|
|
12405
|
-
rslt = rslt.concat(valOrPath);
|
|
12406
|
-
} else {
|
|
12407
|
-
rslt.push(valOrPath);
|
|
12408
|
-
}
|
|
12409
|
-
return rslt;
|
|
12410
|
-
}, []);
|
|
12411
|
-
};
|
|
12412
|
-
JSONPath.prototype._getPreferredOutput = function(ea) {
|
|
12413
|
-
const resultType = this.currResultType;
|
|
12414
|
-
switch (resultType) {
|
|
12415
|
-
case "all": {
|
|
12416
|
-
const path3 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
12417
|
-
ea.pointer = JSONPath.toPointer(path3);
|
|
12418
|
-
ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
|
|
12419
|
-
return ea;
|
|
12420
|
-
}
|
|
12421
|
-
case "value":
|
|
12422
|
-
case "parent":
|
|
12423
|
-
case "parentProperty":
|
|
12424
|
-
return ea[resultType];
|
|
12425
|
-
case "path":
|
|
12426
|
-
return JSONPath.toPathString(ea[resultType]);
|
|
12427
|
-
case "pointer":
|
|
12428
|
-
return JSONPath.toPointer(ea.path);
|
|
12429
|
-
default:
|
|
12430
|
-
throw new TypeError("Unknown result type");
|
|
12431
|
-
}
|
|
12432
|
-
};
|
|
12433
|
-
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type) {
|
|
12434
|
-
if (callback) {
|
|
12435
|
-
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
12436
|
-
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
12437
|
-
callback(preferredOutput, type, fullRetObj);
|
|
12438
|
-
}
|
|
12439
|
-
};
|
|
12440
|
-
JSONPath.prototype._trace = function(expr, val, path3, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
12441
|
-
let retObj;
|
|
12442
|
-
if (!expr.length) {
|
|
12443
|
-
retObj = {
|
|
12444
|
-
path: path3,
|
|
12445
|
-
value: val,
|
|
12446
|
-
parent,
|
|
12447
|
-
parentProperty: parentPropName,
|
|
12448
|
-
hasArrExpr
|
|
12449
|
-
};
|
|
12450
|
-
this._handleCallback(retObj, callback, "value");
|
|
12451
|
-
return retObj;
|
|
12452
|
-
}
|
|
12453
|
-
const loc = expr[0], x = expr.slice(1);
|
|
12454
|
-
const ret = [];
|
|
12455
|
-
function addRet(elems) {
|
|
12456
|
-
if (Array.isArray(elems)) {
|
|
12457
|
-
elems.forEach((t) => {
|
|
12458
|
-
ret.push(t);
|
|
12459
|
-
});
|
|
12460
|
-
} else {
|
|
12461
|
-
ret.push(elems);
|
|
12462
|
-
}
|
|
12463
|
-
}
|
|
12464
|
-
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
12465
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr));
|
|
12466
|
-
} else if (loc === "*") {
|
|
12467
|
-
this._walk(val, (m) => {
|
|
12468
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true, true));
|
|
12469
|
-
});
|
|
12470
|
-
} else if (loc === "..") {
|
|
12471
|
-
addRet(this._trace(x, val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
12472
|
-
this._walk(val, (m) => {
|
|
12473
|
-
if (typeof val[m] === "object") {
|
|
12474
|
-
addRet(this._trace(expr.slice(), val[m], push(path3, m), val, m, callback, true));
|
|
12475
|
-
}
|
|
12476
|
-
});
|
|
12477
|
-
} else if (loc === "^") {
|
|
12478
|
-
this._hasParentSelector = true;
|
|
12479
|
-
return {
|
|
12480
|
-
path: path3.slice(0, -1),
|
|
12481
|
-
expr: x,
|
|
12482
|
-
isParentSelector: true
|
|
12483
|
-
};
|
|
12484
|
-
} else if (loc === "~") {
|
|
12485
|
-
retObj = {
|
|
12486
|
-
path: push(path3, loc),
|
|
12487
|
-
value: parentPropName,
|
|
12488
|
-
parent,
|
|
12489
|
-
parentProperty: null
|
|
12490
|
-
};
|
|
12491
|
-
this._handleCallback(retObj, callback, "property");
|
|
12492
|
-
return retObj;
|
|
12493
|
-
} else if (loc === "$") {
|
|
12494
|
-
addRet(this._trace(x, val, path3, null, null, callback, hasArrExpr));
|
|
12495
|
-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
12496
|
-
addRet(this._slice(loc, x, val, path3, parent, parentPropName, callback));
|
|
12497
|
-
} else if (loc.indexOf("?(") === 0) {
|
|
12498
|
-
if (this.currEval === false) {
|
|
12499
|
-
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
12500
|
-
}
|
|
12501
|
-
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
12502
|
-
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
12503
|
-
if (nested) {
|
|
12504
|
-
this._walk(val, (m) => {
|
|
12505
|
-
const npath = [nested[2]];
|
|
12506
|
-
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
12507
|
-
const filterResults = this._trace(npath, nvalue, path3, parent, parentPropName, callback, true);
|
|
12508
|
-
if (filterResults.length > 0) {
|
|
12509
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
12510
|
-
}
|
|
12511
|
-
});
|
|
12512
|
-
} else {
|
|
12513
|
-
this._walk(val, (m) => {
|
|
12514
|
-
if (this._eval(safeLoc, val[m], m, path3, parent, parentPropName)) {
|
|
12515
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
12516
|
-
}
|
|
12517
|
-
});
|
|
12518
|
-
}
|
|
12519
|
-
} else if (loc[0] === "(") {
|
|
12520
|
-
if (this.currEval === false) {
|
|
12521
|
-
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
12522
|
-
}
|
|
12523
|
-
addRet(this._trace(unshift(this._eval(loc, val, path3.at(-1), path3.slice(0, -1), parent, parentPropName), x), val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
12524
|
-
} else if (loc[0] === "@") {
|
|
12525
|
-
let addType = false;
|
|
12526
|
-
const valueType = loc.slice(1, -2);
|
|
12527
|
-
switch (valueType) {
|
|
12528
|
-
case "scalar":
|
|
12529
|
-
if (!val || !["object", "function"].includes(typeof val)) {
|
|
12530
|
-
addType = true;
|
|
12531
|
-
}
|
|
12532
|
-
break;
|
|
12533
|
-
case "boolean":
|
|
12534
|
-
case "string":
|
|
12535
|
-
case "undefined":
|
|
12536
|
-
case "function":
|
|
12537
|
-
if (typeof val === valueType) {
|
|
12538
|
-
addType = true;
|
|
12539
|
-
}
|
|
12540
|
-
break;
|
|
12541
|
-
case "integer":
|
|
12542
|
-
if (Number.isFinite(val) && !(val % 1)) {
|
|
12543
|
-
addType = true;
|
|
12544
|
-
}
|
|
12545
|
-
break;
|
|
12546
|
-
case "number":
|
|
12547
|
-
if (Number.isFinite(val)) {
|
|
12548
|
-
addType = true;
|
|
12549
|
-
}
|
|
12550
|
-
break;
|
|
12551
|
-
case "nonFinite":
|
|
12552
|
-
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
12553
|
-
addType = true;
|
|
12554
|
-
}
|
|
12555
|
-
break;
|
|
12556
|
-
case "object":
|
|
12557
|
-
if (val && typeof val === valueType) {
|
|
12558
|
-
addType = true;
|
|
12559
|
-
}
|
|
12560
|
-
break;
|
|
12561
|
-
case "array":
|
|
12562
|
-
if (Array.isArray(val)) {
|
|
12563
|
-
addType = true;
|
|
12564
|
-
}
|
|
12565
|
-
break;
|
|
12566
|
-
case "other":
|
|
12567
|
-
addType = this.currOtherTypeCallback(val, path3, parent, parentPropName);
|
|
12568
|
-
break;
|
|
12569
|
-
case "null":
|
|
12570
|
-
if (val === null) {
|
|
12571
|
-
addType = true;
|
|
12572
|
-
}
|
|
12573
|
-
break;
|
|
12574
|
-
default:
|
|
12575
|
-
throw new TypeError("Unknown value type " + valueType);
|
|
12576
|
-
}
|
|
12577
|
-
if (addType) {
|
|
12578
|
-
retObj = {
|
|
12579
|
-
path: path3,
|
|
12580
|
-
value: val,
|
|
12581
|
-
parent,
|
|
12582
|
-
parentProperty: parentPropName
|
|
12583
|
-
};
|
|
12584
|
-
this._handleCallback(retObj, callback, "value");
|
|
12585
|
-
return retObj;
|
|
12586
|
-
}
|
|
12587
|
-
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
12588
|
-
const locProp = loc.slice(1);
|
|
12589
|
-
addRet(this._trace(x, val[locProp], push(path3, locProp), val, locProp, callback, hasArrExpr, true));
|
|
12590
|
-
} else if (loc.includes(",")) {
|
|
12591
|
-
const parts = loc.split(",");
|
|
12592
|
-
for (const part of parts) {
|
|
12593
|
-
addRet(this._trace(unshift(part, x), val, path3, parent, parentPropName, callback, true));
|
|
12594
|
-
}
|
|
12595
|
-
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
12596
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr, true));
|
|
12597
|
-
}
|
|
12598
|
-
if (this._hasParentSelector) {
|
|
12599
|
-
for (let t = 0;t < ret.length; t++) {
|
|
12600
|
-
const rett = ret[t];
|
|
12601
|
-
if (rett && rett.isParentSelector) {
|
|
12602
|
-
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
12603
|
-
if (Array.isArray(tmp)) {
|
|
12604
|
-
ret[t] = tmp[0];
|
|
12605
|
-
const tl = tmp.length;
|
|
12606
|
-
for (let tt = 1;tt < tl; tt++) {
|
|
12607
|
-
t++;
|
|
12608
|
-
ret.splice(t, 0, tmp[tt]);
|
|
12609
|
-
}
|
|
12610
|
-
} else {
|
|
12611
|
-
ret[t] = tmp;
|
|
12612
|
-
}
|
|
12613
|
-
}
|
|
12614
|
-
}
|
|
12615
|
-
}
|
|
12616
|
-
return ret;
|
|
12617
|
-
};
|
|
12618
|
-
JSONPath.prototype._walk = function(val, f) {
|
|
12619
|
-
if (Array.isArray(val)) {
|
|
12620
|
-
const n = val.length;
|
|
12621
|
-
for (let i = 0;i < n; i++) {
|
|
12622
|
-
f(i);
|
|
12623
|
-
}
|
|
12624
|
-
} else if (val && typeof val === "object") {
|
|
12625
|
-
Object.keys(val).forEach((m) => {
|
|
12626
|
-
f(m);
|
|
12627
|
-
});
|
|
12628
|
-
}
|
|
12629
|
-
};
|
|
12630
|
-
JSONPath.prototype._slice = function(loc, expr, val, path3, parent, parentPropName, callback) {
|
|
12631
|
-
if (!Array.isArray(val)) {
|
|
12632
|
-
return;
|
|
12633
|
-
}
|
|
12634
|
-
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
12635
|
-
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
12636
|
-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
12637
|
-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
12638
|
-
const ret = [];
|
|
12639
|
-
for (let i = start;i < end; i += step) {
|
|
12640
|
-
const tmp = this._trace(unshift(i, expr), val, path3, parent, parentPropName, callback, true);
|
|
12641
|
-
tmp.forEach((t) => {
|
|
12642
|
-
ret.push(t);
|
|
12643
|
-
});
|
|
12644
|
-
}
|
|
12645
|
-
return ret;
|
|
12646
|
-
};
|
|
12647
|
-
JSONPath.prototype._eval = function(code, _v, _vname, path3, parent, parentPropName) {
|
|
12648
|
-
this.currSandbox._$_parentProperty = parentPropName;
|
|
12649
|
-
this.currSandbox._$_parent = parent;
|
|
12650
|
-
this.currSandbox._$_property = _vname;
|
|
12651
|
-
this.currSandbox._$_root = this.json;
|
|
12652
|
-
this.currSandbox._$_v = _v;
|
|
12653
|
-
const containsPath = code.includes("@path");
|
|
12654
|
-
if (containsPath) {
|
|
12655
|
-
this.currSandbox._$_path = JSONPath.toPathString(path3.concat([_vname]));
|
|
12656
|
-
}
|
|
12657
|
-
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
12658
|
-
if (!JSONPath.cache[scriptCacheKey]) {
|
|
12659
|
-
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
12660
|
-
if (containsPath) {
|
|
12661
|
-
script = script.replaceAll("@path", "_$_path");
|
|
12662
|
-
}
|
|
12663
|
-
if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
|
|
12664
|
-
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
12665
|
-
} else if (this.currEval === "native") {
|
|
12666
|
-
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
12667
|
-
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
12668
|
-
const CurrEval = this.currEval;
|
|
12669
|
-
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
12670
|
-
} else if (typeof this.currEval === "function") {
|
|
12671
|
-
JSONPath.cache[scriptCacheKey] = {
|
|
12672
|
-
runInNewContext: (context) => this.currEval(script, context)
|
|
12673
|
-
};
|
|
12674
|
-
} else {
|
|
12675
|
-
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
12676
|
-
}
|
|
12677
|
-
}
|
|
12678
|
-
try {
|
|
12679
|
-
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
12680
|
-
} catch (e) {
|
|
12681
|
-
if (this.ignoreEvalErrors) {
|
|
12682
|
-
return false;
|
|
12683
|
-
}
|
|
12684
|
-
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
12685
|
-
}
|
|
12686
|
-
};
|
|
12687
|
-
JSONPath.cache = {};
|
|
12688
|
-
JSONPath.toPathString = function(pathArr) {
|
|
12689
|
-
const x = pathArr, n = x.length;
|
|
12690
|
-
let p = "$";
|
|
12691
|
-
for (let i = 1;i < n; i++) {
|
|
12692
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
12693
|
-
p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
|
|
12694
|
-
}
|
|
12695
|
-
}
|
|
12696
|
-
return p;
|
|
12697
|
-
};
|
|
12698
|
-
JSONPath.toPointer = function(pointer) {
|
|
12699
|
-
const x = pointer, n = x.length;
|
|
12700
|
-
let p = "";
|
|
12701
|
-
for (let i = 1;i < n; i++) {
|
|
12702
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
12703
|
-
p += "/" + x[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
12704
|
-
}
|
|
12705
|
-
}
|
|
12706
|
-
return p;
|
|
12707
|
-
};
|
|
12708
|
-
JSONPath.toPathArray = function(expr) {
|
|
12709
|
-
const {
|
|
12710
|
-
cache
|
|
12711
|
-
} = JSONPath;
|
|
12712
|
-
if (cache[expr]) {
|
|
12713
|
-
return cache[expr].concat();
|
|
12714
|
-
}
|
|
12715
|
-
const subx = [];
|
|
12716
|
-
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
12717
|
-
return "[#" + (subx.push($1) - 1) + "]";
|
|
12718
|
-
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
12719
|
-
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
12720
|
-
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
12721
|
-
return ";" + ups.split("").join(";") + ";";
|
|
12722
|
-
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
12723
|
-
const exprList = normalized.split(";").map(function(exp) {
|
|
12724
|
-
const match = exp.match(/#(\d+)/u);
|
|
12725
|
-
return !match || !match[1] ? exp : subx[match[1]];
|
|
12726
|
-
});
|
|
12727
|
-
cache[expr] = exprList;
|
|
12728
|
-
return cache[expr].concat();
|
|
12729
|
-
};
|
|
12730
|
-
JSONPath.prototype.safeVm = {
|
|
12731
|
-
Script: SafeScript
|
|
12732
|
-
};
|
|
12733
|
-
JSONPath.prototype.vm = vm;
|
|
12734
11375
|
// ../common/src/polling/types.ts
|
|
12735
11376
|
var PollOutcome = {
|
|
12736
11377
|
Completed: "completed",
|
|
@@ -12765,6 +11406,17 @@ var FAILURE_STATUSES = new Set([
|
|
|
12765
11406
|
"canceled",
|
|
12766
11407
|
"stopped"
|
|
12767
11408
|
]);
|
|
11409
|
+
// ../common/src/preview.ts
|
|
11410
|
+
var previewSlot = singleton("PreviewBuild");
|
|
11411
|
+
function isPreviewBuild() {
|
|
11412
|
+
return previewSlot.get(false) ?? false;
|
|
11413
|
+
}
|
|
11414
|
+
Command.prototype.previewCommand = function(nameAndArgs, opts) {
|
|
11415
|
+
if (isPreviewBuild()) {
|
|
11416
|
+
return this.command(nameAndArgs, opts);
|
|
11417
|
+
}
|
|
11418
|
+
return new Command(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
|
|
11419
|
+
};
|
|
12768
11420
|
// ../common/src/screen-logger.ts
|
|
12769
11421
|
var ScreenLogger;
|
|
12770
11422
|
((ScreenLogger) => {
|
|
@@ -12813,13 +11465,13 @@ function validateUipxFile(parsed, uipxFileName) {
|
|
|
12813
11465
|
if (!Array.isArray(parsed.Projects) || parsed.Projects.length === 0) {
|
|
12814
11466
|
throw new Error("Invalid .uipx file: missing Projects.");
|
|
12815
11467
|
}
|
|
12816
|
-
for (const [
|
|
11468
|
+
for (const [index, project] of parsed.Projects.entries()) {
|
|
12817
11469
|
if (!isRecord(project)) {
|
|
12818
|
-
throw new Error(`Invalid .uipx file: Projects[${
|
|
11470
|
+
throw new Error(`Invalid .uipx file: Projects[${index}] must be an object.`);
|
|
12819
11471
|
}
|
|
12820
11472
|
if (typeof project.ProjectRelativePath !== "string" || !project.ProjectRelativePath.trim()) {
|
|
12821
11473
|
const pathHint = typeof project.Path === "string" ? " Found Path, but .uipx uses ProjectRelativePath." : "";
|
|
12822
|
-
throw new Error(`Invalid .uipx file: Projects[${
|
|
11474
|
+
throw new Error(`Invalid .uipx file: Projects[${index}] is missing ProjectRelativePath.${pathHint} Use 'uip solution project add' to add projects, or set ProjectRelativePath to the project file path, for example "Foo/project.uiproj".`);
|
|
12823
11475
|
}
|
|
12824
11476
|
}
|
|
12825
11477
|
return parsed;
|
|
@@ -13133,17 +11785,17 @@ async function readSolutionManifest(fs7, solutionFile) {
|
|
|
13133
11785
|
];
|
|
13134
11786
|
}
|
|
13135
11787
|
const projects = [];
|
|
13136
|
-
for (const [
|
|
11788
|
+
for (const [index, project] of parsed.Projects.entries()) {
|
|
13137
11789
|
if (!isRecord(project)) {
|
|
13138
11790
|
return [
|
|
13139
|
-
new Error(`Invalid solution file: Projects[${
|
|
11791
|
+
new Error(`Invalid solution file: Projects[${index}] must be an object.`),
|
|
13140
11792
|
null
|
|
13141
11793
|
];
|
|
13142
11794
|
}
|
|
13143
11795
|
const projectRelativePath = readString(project.ProjectRelativePath);
|
|
13144
11796
|
if (!projectRelativePath) {
|
|
13145
11797
|
return [
|
|
13146
|
-
new Error(`Invalid solution file: Projects[${
|
|
11798
|
+
new Error(`Invalid solution file: Projects[${index}] is missing ProjectRelativePath. Use 'uip solution project add' to repair the manifest.`),
|
|
13147
11799
|
null
|
|
13148
11800
|
];
|
|
13149
11801
|
}
|
|
@@ -13217,9 +11869,11 @@ async function canonicalizePath(fs7, p) {
|
|
|
13217
11869
|
// ../../node_modules/fflate/esm/index.mjs
|
|
13218
11870
|
import { createRequire as createRequire2 } from "module";
|
|
13219
11871
|
var require2 = createRequire2("/");
|
|
11872
|
+
var _a;
|
|
13220
11873
|
var Worker;
|
|
11874
|
+
var isMarkedAsUntransferable;
|
|
13221
11875
|
try {
|
|
13222
|
-
|
|
11876
|
+
_a = require2("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
|
|
13223
11877
|
} catch (e) {}
|
|
13224
11878
|
var u8 = Uint8Array;
|
|
13225
11879
|
var u16 = Uint16Array;
|
|
@@ -13705,7 +12359,7 @@ var fltn = function(d, p, t, o) {
|
|
|
13705
12359
|
var val = d[k], n = p + k, op = o;
|
|
13706
12360
|
if (Array.isArray(val))
|
|
13707
12361
|
op = mrg(o, val[1]), val = val[0];
|
|
13708
|
-
if (val
|
|
12362
|
+
if (ArrayBuffer.isView(val))
|
|
13709
12363
|
t[n] = [val, op];
|
|
13710
12364
|
else {
|
|
13711
12365
|
t[n += "/"] = [new u8(0), op];
|
|
@@ -13862,6 +12516,17 @@ var DEFAULT_EXCLUDED_DIR_NAMES = new Set([
|
|
|
13862
12516
|
"__pycache__",
|
|
13863
12517
|
".git"
|
|
13864
12518
|
]);
|
|
12519
|
+
var DEFAULT_EXCLUDED_FILE_PATTERNS = [
|
|
12520
|
+
/^\.env($|\..+)/
|
|
12521
|
+
];
|
|
12522
|
+
function isDefaultExcludedFileName(name) {
|
|
12523
|
+
for (const pattern of DEFAULT_EXCLUDED_FILE_PATTERNS) {
|
|
12524
|
+
if (pattern.test(name)) {
|
|
12525
|
+
return true;
|
|
12526
|
+
}
|
|
12527
|
+
}
|
|
12528
|
+
return false;
|
|
12529
|
+
}
|
|
13865
12530
|
var UIPIGNORE_FILENAME = ".uipignore";
|
|
13866
12531
|
function parseUipignore(body) {
|
|
13867
12532
|
const names = new Set;
|
|
@@ -13903,6 +12568,9 @@ async function collectTree(fs7, dir, options = {}) {
|
|
|
13903
12568
|
}
|
|
13904
12569
|
await walk(fullPath, false);
|
|
13905
12570
|
} else if (entryStat?.isFile()) {
|
|
12571
|
+
if (isDefaultExcludedFileName(entryName)) {
|
|
12572
|
+
continue;
|
|
12573
|
+
}
|
|
13906
12574
|
files.push(fullPath);
|
|
13907
12575
|
}
|
|
13908
12576
|
}
|
|
@@ -13934,8 +12602,8 @@ async function createZipFromDir(fs7, dir, options = {}) {
|
|
|
13934
12602
|
}
|
|
13935
12603
|
|
|
13936
12604
|
// src/bundle-service.ts
|
|
13937
|
-
async function readUipignore(fs7,
|
|
13938
|
-
const ignorePath = fs7.path.join(
|
|
12605
|
+
async function readUipignore(fs7, dir) {
|
|
12606
|
+
const ignorePath = fs7.path.join(dir, UIPIGNORE_FILENAME);
|
|
13939
12607
|
if (!await fs7.exists(ignorePath)) {
|
|
13940
12608
|
return new Set;
|
|
13941
12609
|
}
|
|
@@ -13950,6 +12618,18 @@ async function readUipignore(fs7, solutionDir) {
|
|
|
13950
12618
|
return new Set;
|
|
13951
12619
|
}
|
|
13952
12620
|
}
|
|
12621
|
+
async function mergeProjectUipignore(fs7, projectPath, projectLabel, solutionExcludeDirs) {
|
|
12622
|
+
const projectExtra = await readUipignore(fs7, projectPath);
|
|
12623
|
+
if (projectExtra.size === 0) {
|
|
12624
|
+
return solutionExcludeDirs;
|
|
12625
|
+
}
|
|
12626
|
+
const merged = new Set(solutionExcludeDirs);
|
|
12627
|
+
for (const name of projectExtra) {
|
|
12628
|
+
merged.add(name);
|
|
12629
|
+
}
|
|
12630
|
+
logger.info(`[${projectLabel}] Applying ${projectExtra.size} extra exclude(s) from project ${UIPIGNORE_FILENAME}: ${[...projectExtra].join(", ")}`);
|
|
12631
|
+
return merged;
|
|
12632
|
+
}
|
|
13953
12633
|
var toForwardSlash = (p) => p.replace(/\\/g, "/");
|
|
13954
12634
|
async function mirrorTree(fs7, srcDir, relativeBase, destBaseDir, additionalExcludeDirs) {
|
|
13955
12635
|
const { files, emptyDirs } = await collectTree(fs7, srcDir, {
|
|
@@ -13996,6 +12676,9 @@ async function flattenProjectDir(fs7, srcProjectDir, destProjectDir, additionalE
|
|
|
13996
12676
|
continue;
|
|
13997
12677
|
}
|
|
13998
12678
|
if (entryStat.isFile()) {
|
|
12679
|
+
if (isDefaultExcludedFileName(entryName)) {
|
|
12680
|
+
continue;
|
|
12681
|
+
}
|
|
13999
12682
|
const data = await fs7.readFile(srcPath);
|
|
14000
12683
|
if (data) {
|
|
14001
12684
|
await fs7.writeFile(fs7.path.join(destProjectDir, entryName), data);
|
|
@@ -14053,7 +12736,8 @@ async function bundleSolution(fs7, solutionDir, outputDir, outputName) {
|
|
|
14053
12736
|
if (!projectStat) {
|
|
14054
12737
|
throw new Error(`Project directory not found: ${srcProjectPath}`);
|
|
14055
12738
|
}
|
|
14056
|
-
await
|
|
12739
|
+
const projectExcludeDirs = await mergeProjectUipignore(fs7, srcProjectPath, projectDir, additionalExcludeDirs);
|
|
12740
|
+
await flattenProjectDir(fs7, srcProjectPath, fs7.path.join(stagingDir, projectDir), projectExcludeDirs);
|
|
14057
12741
|
}
|
|
14058
12742
|
const resourcesPath = fs7.path.join(resolvedPath, "resources");
|
|
14059
12743
|
if (!effectiveExclude.has("resources") && await fs7.exists(resourcesPath)) {
|
|
@@ -15610,3 +14294,5 @@ export {
|
|
|
15610
14294
|
BaseAPI,
|
|
15611
14295
|
BASE_PATH
|
|
15612
14296
|
};
|
|
14297
|
+
|
|
14298
|
+
//# debugId=3D77544CD633DA3364756E2164756E21
|