@poe-platform/safe-bash 0.1.508 → 0.1.509
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/safe-bash/chunks/chunk-4OKU6JXB.js +5279 -0
- package/dist/safe-bash/chunks/chunk-4OKU6JXB.js.map +7 -0
- package/dist/safe-bash/chunks/chunk-5HT35GTV.js +520 -0
- package/dist/safe-bash/chunks/chunk-5HT35GTV.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-3ISDVRIM.js → chunk-B637PJBS.js} +19 -523
- package/dist/safe-bash/chunks/chunk-B637PJBS.js.map +7 -0
- package/dist/safe-bash/commands/structured/query-core.d.ts +35 -0
- package/dist/safe-bash/commands/structured/query-core.d.ts.map +1 -0
- package/dist/safe-bash/commands/structured/query-core.js +588 -0
- package/dist/safe-bash/commands/structured/query-core.js.map +1 -0
- package/dist/safe-bash/commands/xml/index.browser.js +2 -1
- package/dist/safe-bash/commands/yq/accounting.d.ts +64 -0
- package/dist/safe-bash/commands/yq/accounting.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/accounting.js +257 -0
- package/dist/safe-bash/commands/yq/accounting.js.map +1 -0
- package/dist/safe-bash/commands/yq/encoder.d.ts +6 -0
- package/dist/safe-bash/commands/yq/encoder.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/encoder.js +240 -0
- package/dist/safe-bash/commands/yq/encoder.js.map +1 -0
- package/dist/safe-bash/commands/yq/errors.d.ts +15 -0
- package/dist/safe-bash/commands/yq/errors.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/errors.js +37 -0
- package/dist/safe-bash/commands/yq/errors.js.map +1 -0
- package/dist/safe-bash/commands/yq/index.browser.js +12 -0
- package/dist/safe-bash/commands/yq/index.browser.js.map +7 -0
- package/dist/safe-bash/commands/yq/index.d.ts +9 -0
- package/dist/safe-bash/commands/yq/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/index.js +719 -0
- package/dist/safe-bash/commands/yq/index.js.map +1 -0
- package/dist/safe-bash/commands/yq/parser.d.ts +5 -0
- package/dist/safe-bash/commands/yq/parser.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/parser.js +1326 -0
- package/dist/safe-bash/commands/yq/parser.js.map +1 -0
- package/dist/safe-bash/commands/yq/toml.d.ts +5 -0
- package/dist/safe-bash/commands/yq/toml.d.ts.map +1 -0
- package/dist/safe-bash/commands/yq/toml.js +690 -0
- package/dist/safe-bash/commands/yq/toml.js.map +1 -0
- package/dist/safe-bash/core.browser.js +221 -2171
- package/dist/safe-bash/core.browser.js.map +4 -4
- package/dist/safe-bash/core.d.ts +1 -0
- package/dist/safe-bash/core.d.ts.map +1 -1
- package/dist/safe-bash/core.js +1 -0
- package/dist/safe-bash/core.js.map +1 -1
- package/package.json +8 -2
- package/dist/safe-bash/chunks/chunk-3ISDVRIM.js.map +0 -7
|
@@ -1620,14 +1620,14 @@ var require_buffer = __commonJS({
|
|
|
1620
1620
|
);
|
|
1621
1621
|
E(
|
|
1622
1622
|
"ERR_OUT_OF_RANGE",
|
|
1623
|
-
function(str, range,
|
|
1623
|
+
function(str, range, input2) {
|
|
1624
1624
|
let msg = `The value of "${str}" is out of range.`;
|
|
1625
|
-
let received =
|
|
1626
|
-
if (Number.isInteger(
|
|
1627
|
-
received = addNumericalSeparator(String(
|
|
1628
|
-
} else if (typeof
|
|
1629
|
-
received = String(
|
|
1630
|
-
if (
|
|
1625
|
+
let received = input2;
|
|
1626
|
+
if (Number.isInteger(input2) && Math.abs(input2) > 2 ** 32) {
|
|
1627
|
+
received = addNumericalSeparator(String(input2));
|
|
1628
|
+
} else if (typeof input2 === "bigint") {
|
|
1629
|
+
received = String(input2);
|
|
1630
|
+
if (input2 > BigInt(2) ** BigInt(32) || input2 < -(BigInt(2) ** BigInt(32))) {
|
|
1631
1631
|
received = addNumericalSeparator(received);
|
|
1632
1632
|
}
|
|
1633
1633
|
received += "n";
|
|
@@ -1826,13 +1826,6 @@ var init_platform = __esm({
|
|
|
1826
1826
|
}
|
|
1827
1827
|
});
|
|
1828
1828
|
|
|
1829
|
-
// packages/safe-bash/src/commands/xml/index.ts
|
|
1830
|
-
init_platform();
|
|
1831
|
-
import { parseXmlSteps, XmlLimitError } from "@poe-platform/safe-fs/core";
|
|
1832
|
-
|
|
1833
|
-
// packages/safe-bash/src/contracts/command.ts
|
|
1834
|
-
init_platform();
|
|
1835
|
-
|
|
1836
1829
|
// packages/safe-bash/src/contracts/value.ts
|
|
1837
1830
|
init_platform();
|
|
1838
1831
|
var byteValues = /* @__PURE__ */ new WeakMap();
|
|
@@ -2020,6 +2013,7 @@ function encodeValues(values, output2) {
|
|
|
2020
2013
|
}
|
|
2021
2014
|
|
|
2022
2015
|
// packages/safe-bash/src/contracts/command.ts
|
|
2016
|
+
init_platform();
|
|
2023
2017
|
var argumentCarriers = /* @__PURE__ */ new WeakSet();
|
|
2024
2018
|
var CommandArgumentIdentityError = class extends TypeError {
|
|
2025
2019
|
constructor() {
|
|
@@ -2184,17 +2178,17 @@ var CommandRegistry = class {
|
|
|
2184
2178
|
for (const command of commands) this.register(command);
|
|
2185
2179
|
}
|
|
2186
2180
|
register(command, options2 = {}) {
|
|
2187
|
-
const { name, execute
|
|
2181
|
+
const { name, execute } = command;
|
|
2188
2182
|
if (typeof name !== "string" || !name || /[\s/\0]/u.test(name)) {
|
|
2189
2183
|
throw new TypeError("Command names must be nonempty and contain no whitespace, slash, or NUL");
|
|
2190
2184
|
}
|
|
2191
|
-
if (typeof
|
|
2185
|
+
if (typeof execute !== "function") {
|
|
2192
2186
|
throw new TypeError("Command execute must be a function");
|
|
2193
2187
|
}
|
|
2194
2188
|
if (this.#commands.has(name) && !options2.replace) {
|
|
2195
2189
|
throw new Error(`Command already registered: ${name}`);
|
|
2196
2190
|
}
|
|
2197
|
-
this.#commands.set(name, Object.freeze({ ...command, name, execute
|
|
2191
|
+
this.#commands.set(name, Object.freeze({ ...command, name, execute }));
|
|
2198
2192
|
return this;
|
|
2199
2193
|
}
|
|
2200
2194
|
get(name) {
|
|
@@ -2217,14 +2211,12 @@ function validateExitCode(exitCode) {
|
|
|
2217
2211
|
return exitCode;
|
|
2218
2212
|
}
|
|
2219
2213
|
|
|
2220
|
-
// packages/safe-bash/src/contracts/command-requirements.ts
|
|
2221
|
-
init_platform();
|
|
2222
|
-
|
|
2223
2214
|
// packages/safe-bash/src/contracts/errors.ts
|
|
2224
2215
|
init_platform();
|
|
2225
2216
|
import { isErrnoCode, isFsError, toFsError, FsError } from "@poe-platform/safe-fs/core";
|
|
2226
2217
|
|
|
2227
2218
|
// packages/safe-bash/src/contracts/command-requirements.ts
|
|
2219
|
+
init_platform();
|
|
2228
2220
|
function evaluateMode(requirement, capabilities) {
|
|
2229
2221
|
const missing = requirement.capabilities.filter((name) => capabilities[name] === false);
|
|
2230
2222
|
const unknown = requirement.capabilities.filter((name) => capabilities[name] === void 0);
|
|
@@ -2420,12 +2412,12 @@ async function abortable(operation, signal) {
|
|
|
2420
2412
|
});
|
|
2421
2413
|
}
|
|
2422
2414
|
|
|
2423
|
-
// packages/safe-bash/src/
|
|
2415
|
+
// packages/safe-bash/src/escaping.ts
|
|
2424
2416
|
init_platform();
|
|
2425
|
-
import { validatePath, resolvePath, normalizePath, relativePath, isPathWithin, assertPathWithin, basename, dirname, extname, joinPath, isAbsolutePath, posixPath as posixPath2 } from "@poe-platform/safe-fs/core";
|
|
2426
2417
|
|
|
2427
|
-
// packages/safe-bash/src/
|
|
2418
|
+
// packages/safe-bash/src/contracts/path.ts
|
|
2428
2419
|
init_platform();
|
|
2420
|
+
import { validatePath, resolvePath, normalizePath, relativePath, isPathWithin, assertPathWithin, basename, dirname, extname, joinPath, isAbsolutePath, posixPath as posixPath2 } from "@poe-platform/safe-fs/core";
|
|
2429
2421
|
|
|
2430
2422
|
// packages/safe-bash/src/contracts/yield.ts
|
|
2431
2423
|
init_platform();
|
|
@@ -3212,501 +3204,6 @@ async function interruptible(operation, signal) {
|
|
|
3212
3204
|
});
|
|
3213
3205
|
}
|
|
3214
3206
|
|
|
3215
|
-
// packages/safe-bash/src/commands/xml/limits.ts
|
|
3216
|
-
init_platform();
|
|
3217
|
-
var defaultXmlQueryLimits = Object.freeze({
|
|
3218
|
-
maxInputBytes: 8 * 1024 * 1024,
|
|
3219
|
-
maxOutputBytes: 8 * 1024 * 1024,
|
|
3220
|
-
maxSourceBytes: 64 * 1024,
|
|
3221
|
-
maxDepth: 64,
|
|
3222
|
-
maxNodes: 1e5,
|
|
3223
|
-
maxAttributes: 1e4,
|
|
3224
|
-
maxAttributesPerElement: 128,
|
|
3225
|
-
maxNamespaces: 256,
|
|
3226
|
-
maxSteps: 1e6,
|
|
3227
|
-
maxResults: 1e5
|
|
3228
|
-
});
|
|
3229
|
-
var XmlQueryError = class extends Error {
|
|
3230
|
-
constructor(message, status) {
|
|
3231
|
-
super(message);
|
|
3232
|
-
this.status = status;
|
|
3233
|
-
}
|
|
3234
|
-
status;
|
|
3235
|
-
};
|
|
3236
|
-
var XmlQueryLimitError = class extends XmlQueryError {
|
|
3237
|
-
constructor(name) {
|
|
3238
|
-
super(`${name} limit exceeded`, 5);
|
|
3239
|
-
}
|
|
3240
|
-
};
|
|
3241
|
-
function resolveXmlQueryLimits(options2 = {}) {
|
|
3242
|
-
const limits = { ...defaultXmlQueryLimits, ...options2 };
|
|
3243
|
-
for (const [name, value2] of Object.entries(limits)) {
|
|
3244
|
-
if (!Object.hasOwn(defaultXmlQueryLimits, name) || !Number.isSafeInteger(value2) || value2 < 1) {
|
|
3245
|
-
throw new RangeError(`${name} must be a positive safe integer XML limit`);
|
|
3246
|
-
}
|
|
3247
|
-
}
|
|
3248
|
-
if (limits.maxDepth > 256) throw new RangeError("maxDepth must be <=256");
|
|
3249
|
-
return Object.freeze(limits);
|
|
3250
|
-
}
|
|
3251
|
-
var XmlBudget = class {
|
|
3252
|
-
constructor(limits, signal) {
|
|
3253
|
-
this.limits = limits;
|
|
3254
|
-
this.signal = signal;
|
|
3255
|
-
}
|
|
3256
|
-
limits;
|
|
3257
|
-
signal;
|
|
3258
|
-
steps = 0;
|
|
3259
|
-
checkpoint = 0;
|
|
3260
|
-
outputBytes = 0;
|
|
3261
|
-
async tick(work = 1) {
|
|
3262
|
-
this.signal.throwIfAborted();
|
|
3263
|
-
this.steps += work;
|
|
3264
|
-
if (this.steps > this.limits.maxSteps) throw new XmlQueryLimitError("maxSteps");
|
|
3265
|
-
this.checkpoint += work;
|
|
3266
|
-
if (this.checkpoint >= 1024) {
|
|
3267
|
-
this.checkpoint = 0;
|
|
3268
|
-
await yieldTurn(this.signal);
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
results(size) {
|
|
3272
|
-
if (size > this.limits.maxResults) throw new XmlQueryLimitError("maxResults");
|
|
3273
|
-
}
|
|
3274
|
-
};
|
|
3275
|
-
|
|
3276
|
-
// packages/safe-bash/src/commands/xml/query.ts
|
|
3277
|
-
init_platform();
|
|
3278
|
-
var nameStart = (character) => character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character === "_";
|
|
3279
|
-
var namePart = (character) => nameStart(character) || character >= "0" && character <= "9" || character === "-" || character === ".";
|
|
3280
|
-
async function parseQuery(source, budget) {
|
|
3281
|
-
if (source.length > budget.limits.maxSourceBytes || import_buffer.Buffer.byteLength(source) > budget.limits.maxSourceBytes) throw new XmlQueryLimitError("maxSourceBytes");
|
|
3282
|
-
for (let offset = 0; offset < source.length; offset += 256) await budget.tick(Math.min(256, source.length - offset));
|
|
3283
|
-
let at = 0;
|
|
3284
|
-
const fail = () => {
|
|
3285
|
-
throw new XmlQueryError(`unsupported XPath syntax at offset ${at}`, 10);
|
|
3286
|
-
};
|
|
3287
|
-
const space = () => {
|
|
3288
|
-
while (source[at] === " " || source[at] === " " || source[at] === "\r" || source[at] === "\n") at++;
|
|
3289
|
-
};
|
|
3290
|
-
const expect = (value2) => {
|
|
3291
|
-
space();
|
|
3292
|
-
if (!source.startsWith(value2, at)) fail();
|
|
3293
|
-
at += value2.length;
|
|
3294
|
-
};
|
|
3295
|
-
const name = () => {
|
|
3296
|
-
space();
|
|
3297
|
-
const start = at;
|
|
3298
|
-
if (!nameStart(source[at] ?? "")) fail();
|
|
3299
|
-
while (namePart(source[at] ?? "")) at++;
|
|
3300
|
-
if (source[at] === ":") fail();
|
|
3301
|
-
return source.slice(start, at);
|
|
3302
|
-
};
|
|
3303
|
-
space();
|
|
3304
|
-
let scalar;
|
|
3305
|
-
if (source[at] !== "/") {
|
|
3306
|
-
const value2 = name();
|
|
3307
|
-
if (value2 !== "string" && value2 !== "count" && value2 !== "boolean") fail();
|
|
3308
|
-
scalar = value2;
|
|
3309
|
-
expect("(");
|
|
3310
|
-
}
|
|
3311
|
-
const steps = [];
|
|
3312
|
-
space();
|
|
3313
|
-
while (source[at] === "/") {
|
|
3314
|
-
at++;
|
|
3315
|
-
const descendant = source[at] === "/";
|
|
3316
|
-
if (descendant) at++;
|
|
3317
|
-
space();
|
|
3318
|
-
let kind = "element";
|
|
3319
|
-
if (source[at] === "@") {
|
|
3320
|
-
kind = "attribute";
|
|
3321
|
-
at++;
|
|
3322
|
-
}
|
|
3323
|
-
let selected;
|
|
3324
|
-
if (source[at] === "*") {
|
|
3325
|
-
selected = "*";
|
|
3326
|
-
at++;
|
|
3327
|
-
} else {
|
|
3328
|
-
selected = name();
|
|
3329
|
-
space();
|
|
3330
|
-
if (source[at] === "(") {
|
|
3331
|
-
if (selected !== "text" || kind !== "element") fail();
|
|
3332
|
-
expect("(");
|
|
3333
|
-
expect(")");
|
|
3334
|
-
kind = "text";
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
const predicates = [];
|
|
3338
|
-
space();
|
|
3339
|
-
while (source[at] === "[") {
|
|
3340
|
-
at++;
|
|
3341
|
-
space();
|
|
3342
|
-
if (source[at] === "@") {
|
|
3343
|
-
at++;
|
|
3344
|
-
const attribute = name();
|
|
3345
|
-
expect("=");
|
|
3346
|
-
space();
|
|
3347
|
-
const quote = source[at++];
|
|
3348
|
-
if (quote !== "'" && quote !== '"') fail();
|
|
3349
|
-
const start = at;
|
|
3350
|
-
while (at < source.length && source[at] !== quote) at++;
|
|
3351
|
-
if (at === source.length) fail();
|
|
3352
|
-
predicates.push({ kind: "attribute", name: attribute, value: source.slice(start, at++) });
|
|
3353
|
-
} else {
|
|
3354
|
-
const start = at;
|
|
3355
|
-
while ((source[at] ?? "") >= "0" && (source[at] ?? "") <= "9") at++;
|
|
3356
|
-
const value2 = Number(source.slice(start, at));
|
|
3357
|
-
if (start === at || !Number.isSafeInteger(value2) || value2 < 1) fail();
|
|
3358
|
-
predicates.push({ kind: "position", value: value2 });
|
|
3359
|
-
}
|
|
3360
|
-
expect("]");
|
|
3361
|
-
space();
|
|
3362
|
-
}
|
|
3363
|
-
steps.push({ descendant, kind, name: selected, predicates });
|
|
3364
|
-
if (kind !== "element" && source[at] === "/") fail();
|
|
3365
|
-
await budget.tick();
|
|
3366
|
-
}
|
|
3367
|
-
if (!steps.length) fail();
|
|
3368
|
-
if (scalar !== void 0) expect(")");
|
|
3369
|
-
space();
|
|
3370
|
-
if (at !== source.length) fail();
|
|
3371
|
-
return { scalar, steps };
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
// packages/safe-bash/src/commands/xml/evaluate.ts
|
|
3375
|
-
init_platform();
|
|
3376
|
-
var xmlns = "http://www.w3.org/2000/xmlns/";
|
|
3377
|
-
async function indexTree(root, budget) {
|
|
3378
|
-
const document = { kind: "document", children: [] };
|
|
3379
|
-
const order = [document];
|
|
3380
|
-
const pending = [{ parent: document, content: root }];
|
|
3381
|
-
while (pending.length) {
|
|
3382
|
-
await budget.tick();
|
|
3383
|
-
const { parent, content } = pending.pop();
|
|
3384
|
-
if (content.kind === "element") {
|
|
3385
|
-
const node = { kind: "element", value: content, children: [], attributes: [] };
|
|
3386
|
-
parent.children.push(node);
|
|
3387
|
-
order.push(node);
|
|
3388
|
-
for (const attribute of content.attributes) {
|
|
3389
|
-
await budget.tick();
|
|
3390
|
-
if (attribute.namespace === xmlns) continue;
|
|
3391
|
-
const selected = { kind: "attribute", value: attribute };
|
|
3392
|
-
node.attributes.push(selected);
|
|
3393
|
-
order.push(selected);
|
|
3394
|
-
}
|
|
3395
|
-
for (let index = content.content.length - 1; index >= 0; index--) {
|
|
3396
|
-
await budget.tick();
|
|
3397
|
-
pending.push({ parent: node, content: content.content[index] });
|
|
3398
|
-
}
|
|
3399
|
-
} else {
|
|
3400
|
-
const node = { kind: content.kind, value: content };
|
|
3401
|
-
parent.children.push(node);
|
|
3402
|
-
order.push(node);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
return { document, order };
|
|
3406
|
-
}
|
|
3407
|
-
function matches(node, step) {
|
|
3408
|
-
if (step.kind === "text") return node.kind === "text" || node.kind === "cdata";
|
|
3409
|
-
if (node.kind !== step.kind) return false;
|
|
3410
|
-
if (node.kind === "element" || node.kind === "attribute") {
|
|
3411
|
-
return step.name === "*" || node.value.namespace === "" && node.value.localName === step.name;
|
|
3412
|
-
}
|
|
3413
|
-
return false;
|
|
3414
|
-
}
|
|
3415
|
-
async function evaluate(query, root, budget) {
|
|
3416
|
-
const { document, order } = await indexTree(root, budget);
|
|
3417
|
-
let contexts = [document];
|
|
3418
|
-
for (const step of query.steps) {
|
|
3419
|
-
const parents = /* @__PURE__ */ new Set();
|
|
3420
|
-
const pending = [...contexts];
|
|
3421
|
-
while (pending.length) {
|
|
3422
|
-
await budget.tick();
|
|
3423
|
-
const node = pending.pop();
|
|
3424
|
-
if (parents.has(node)) continue;
|
|
3425
|
-
parents.add(node);
|
|
3426
|
-
if (step.descendant && (node.kind === "document" || node.kind === "element")) {
|
|
3427
|
-
for (const child of node.children) {
|
|
3428
|
-
await budget.tick();
|
|
3429
|
-
pending.push(child);
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
const selected = /* @__PURE__ */ new Set();
|
|
3434
|
-
for (const parent of parents) {
|
|
3435
|
-
await budget.tick();
|
|
3436
|
-
const candidates = step.kind === "attribute" ? parent.kind === "element" ? parent.attributes : [] : parent.kind === "element" || parent.kind === "document" ? parent.children : [];
|
|
3437
|
-
let matched = [];
|
|
3438
|
-
for (const candidate of candidates) {
|
|
3439
|
-
await budget.tick();
|
|
3440
|
-
if (matches(candidate, step)) matched.push(candidate);
|
|
3441
|
-
}
|
|
3442
|
-
for (const predicate of step.predicates) {
|
|
3443
|
-
await budget.tick();
|
|
3444
|
-
if (predicate.kind === "position") matched = matched[predicate.value - 1] ? [matched[predicate.value - 1]] : [];
|
|
3445
|
-
else {
|
|
3446
|
-
const filtered = [];
|
|
3447
|
-
for (const candidate of matched) {
|
|
3448
|
-
await budget.tick();
|
|
3449
|
-
if (candidate.kind !== "element") continue;
|
|
3450
|
-
for (const attribute of candidate.attributes) {
|
|
3451
|
-
await budget.tick(attribute.value.value.length + 1);
|
|
3452
|
-
if (attribute.value.namespace === "" && attribute.value.localName === predicate.name && attribute.value.value === predicate.value) {
|
|
3453
|
-
filtered.push(candidate);
|
|
3454
|
-
break;
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
matched = filtered;
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
for (const node of matched) {
|
|
3462
|
-
await budget.tick();
|
|
3463
|
-
if (!selected.has(node)) {
|
|
3464
|
-
budget.results(selected.size + 1);
|
|
3465
|
-
selected.add(node);
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
contexts = [];
|
|
3470
|
-
for (const node of order) {
|
|
3471
|
-
await budget.tick();
|
|
3472
|
-
if (selected.has(node)) contexts.push(node);
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
return contexts;
|
|
3476
|
-
}
|
|
3477
|
-
async function* stringValue(node, budget) {
|
|
3478
|
-
if (node === void 0) return;
|
|
3479
|
-
if (node.kind === "attribute") {
|
|
3480
|
-
yield node.value.value;
|
|
3481
|
-
return;
|
|
3482
|
-
}
|
|
3483
|
-
const pending = [node];
|
|
3484
|
-
while (pending.length) {
|
|
3485
|
-
await budget.tick();
|
|
3486
|
-
const current = pending.pop();
|
|
3487
|
-
if (current.kind === "element" || current.kind === "document") {
|
|
3488
|
-
for (let index = current.children.length - 1; index >= 0; index--) {
|
|
3489
|
-
await budget.tick();
|
|
3490
|
-
pending.push(current.children[index]);
|
|
3491
|
-
}
|
|
3492
|
-
} else if (current.kind === "text" || current.kind === "cdata") yield current.value.text;
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
async function* serialize(node, budget) {
|
|
3496
|
-
if (node.kind === "attribute") {
|
|
3497
|
-
yield ` ${node.value.name}="`;
|
|
3498
|
-
yield* escape(node.value.value, true, budget);
|
|
3499
|
-
yield '"';
|
|
3500
|
-
return;
|
|
3501
|
-
}
|
|
3502
|
-
if (node.kind === "document") return;
|
|
3503
|
-
const pending = [node.value];
|
|
3504
|
-
while (pending.length) {
|
|
3505
|
-
await budget.tick();
|
|
3506
|
-
const current = pending.pop();
|
|
3507
|
-
if (typeof current === "string") {
|
|
3508
|
-
yield current;
|
|
3509
|
-
continue;
|
|
3510
|
-
}
|
|
3511
|
-
if (current.kind === "element") {
|
|
3512
|
-
yield `<${current.name}`;
|
|
3513
|
-
for (const attribute of current.attributes) {
|
|
3514
|
-
await budget.tick();
|
|
3515
|
-
yield ` ${attribute.name}="`;
|
|
3516
|
-
yield* escape(attribute.value, true, budget);
|
|
3517
|
-
yield '"';
|
|
3518
|
-
}
|
|
3519
|
-
if (!current.content.length) yield "/>";
|
|
3520
|
-
else {
|
|
3521
|
-
yield ">";
|
|
3522
|
-
pending.push(`</${current.name}>`);
|
|
3523
|
-
for (let index = current.content.length - 1; index >= 0; index--) {
|
|
3524
|
-
await budget.tick();
|
|
3525
|
-
pending.push(current.content[index]);
|
|
3526
|
-
}
|
|
3527
|
-
}
|
|
3528
|
-
} else if (current.kind === "text") yield* escape(current.text, false, budget);
|
|
3529
|
-
else if (current.kind === "cdata") {
|
|
3530
|
-
yield "<![CDATA[";
|
|
3531
|
-
yield current.text;
|
|
3532
|
-
yield "]]>";
|
|
3533
|
-
} else if (current.kind === "comment") {
|
|
3534
|
-
yield "<!--";
|
|
3535
|
-
yield current.text;
|
|
3536
|
-
yield "-->";
|
|
3537
|
-
} else if (current.kind === "processing-instruction") {
|
|
3538
|
-
yield `<?${current.target}`;
|
|
3539
|
-
if (current.text) {
|
|
3540
|
-
yield " ";
|
|
3541
|
-
yield current.text;
|
|
3542
|
-
}
|
|
3543
|
-
yield "?>";
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
}
|
|
3547
|
-
async function* escape(value2, attribute, budget) {
|
|
3548
|
-
let part = "";
|
|
3549
|
-
for (const character of value2) {
|
|
3550
|
-
await budget.tick();
|
|
3551
|
-
part += character === "&" ? "&" : character === "<" ? "<" : character === ">" ? ">" : attribute && character === '"' ? """ : attribute && character === "\n" ? " " : character === "\r" ? " " : attribute && character === " " ? "	" : character;
|
|
3552
|
-
if (part.length >= 4096) {
|
|
3553
|
-
yield part;
|
|
3554
|
-
part = "";
|
|
3555
|
-
}
|
|
3556
|
-
}
|
|
3557
|
-
if (part) yield part;
|
|
3558
|
-
}
|
|
3559
|
-
|
|
3560
|
-
// packages/safe-bash/src/commands/xml/index.ts
|
|
3561
|
-
async function argumentsFor(context, budget) {
|
|
3562
|
-
if (context.args.length > 5) throw new XmlQueryError("expected one XML input FILE or -", 2);
|
|
3563
|
-
const carrier = getCommandArguments(context);
|
|
3564
|
-
const args = carrier.args;
|
|
3565
|
-
async function admitted(position, limit) {
|
|
3566
|
-
const text = args[position];
|
|
3567
|
-
if (text.length > budget.limits[limit]) throw new XmlQueryLimitError(limit);
|
|
3568
|
-
const size = shellValueByteLength(carrier.values[position]);
|
|
3569
|
-
if (size > budget.limits[limit]) throw new XmlQueryLimitError(limit);
|
|
3570
|
-
for (let offset = 0; offset < size; offset += 1024) await budget.tick(Math.min(1024, size - offset));
|
|
3571
|
-
let decoded;
|
|
3572
|
-
try {
|
|
3573
|
-
decoded = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(carrier.bytes(position));
|
|
3574
|
-
} catch {
|
|
3575
|
-
throw new XmlQueryError("XPath and filenames require valid UTF-8", 2);
|
|
3576
|
-
}
|
|
3577
|
-
if (decoded !== text) throw new XmlQueryError("XPath and filenames require lossless UTF-8", 2);
|
|
3578
|
-
return decoded;
|
|
3579
|
-
}
|
|
3580
|
-
let index = 0;
|
|
3581
|
-
if (context.command === "xmllint") {
|
|
3582
|
-
if (args[index++] !== "--xpath") throw new XmlQueryError("expected --xpath QUERY [FILE|-]", 2);
|
|
3583
|
-
}
|
|
3584
|
-
if (args[index] === "--") index++;
|
|
3585
|
-
const sourceIndex = index++;
|
|
3586
|
-
const source = args[sourceIndex];
|
|
3587
|
-
if (source === void 0 || source.startsWith("-")) throw new XmlQueryError("expected QUERY [FILE|-]", 2);
|
|
3588
|
-
if (args[index] === "--") index++;
|
|
3589
|
-
const fileIndex = index++;
|
|
3590
|
-
const file = args[fileIndex];
|
|
3591
|
-
if (index < args.length || file !== void 0 && file.startsWith("-") && file !== "-") throw new XmlQueryError("expected one XML input FILE or -", 2);
|
|
3592
|
-
const query = await parseQuery(await admitted(sourceIndex, "maxSourceBytes"), budget);
|
|
3593
|
-
return { query, file: file === void 0 ? void 0 : await admitted(fileIndex, "maxInputBytes") };
|
|
3594
|
-
}
|
|
3595
|
-
async function input2(context, file, budget) {
|
|
3596
|
-
let source = context.stdin;
|
|
3597
|
-
if (file !== void 0 && file !== "-") {
|
|
3598
|
-
const path = pathOf(context, file);
|
|
3599
|
-
const capabilities = context.fs.capabilitiesFor ? await interruptible(() => context.fs.capabilitiesFor(path, { signal: context.signal }), context.signal) : context.fs.capabilities;
|
|
3600
|
-
context.signal.throwIfAborted();
|
|
3601
|
-
if (context.fs.readStream && capabilities.streamingRead !== false) source = context.fs.readStream(path, { signal: context.signal });
|
|
3602
|
-
else {
|
|
3603
|
-
try {
|
|
3604
|
-
source = toByteSource(await interruptible(() => context.fs.readFile(path, { signal: context.signal, maxBytes: budget.limits.maxInputBytes }), context.signal));
|
|
3605
|
-
} catch (error) {
|
|
3606
|
-
context.signal.throwIfAborted();
|
|
3607
|
-
if (error instanceof FsError && error.code === "EFBIG") throw new XmlQueryLimitError("maxInputBytes");
|
|
3608
|
-
throw error;
|
|
3609
|
-
}
|
|
3610
|
-
}
|
|
3611
|
-
}
|
|
3612
|
-
const parts2 = [];
|
|
3613
|
-
let size = 0;
|
|
3614
|
-
const decoder3 = new TextDecoder("utf-8", { fatal: true });
|
|
3615
|
-
for await (const chunk of readBytes2(source, context.signal)) {
|
|
3616
|
-
await budget.tick();
|
|
3617
|
-
size += chunk.byteLength;
|
|
3618
|
-
if (size > budget.limits.maxInputBytes) throw new XmlQueryLimitError("maxInputBytes");
|
|
3619
|
-
for (let offset = 0; offset < chunk.length; offset += 4096) {
|
|
3620
|
-
await budget.tick(Math.min(4096, chunk.length - offset));
|
|
3621
|
-
try {
|
|
3622
|
-
parts2.push(decoder3.decode(chunk.subarray(offset, offset + 4096), { stream: true }));
|
|
3623
|
-
} catch {
|
|
3624
|
-
throw new XmlQueryError("XML input must be UTF-8", 1);
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
}
|
|
3628
|
-
try {
|
|
3629
|
-
parts2.push(decoder3.decode());
|
|
3630
|
-
} catch {
|
|
3631
|
-
throw new XmlQueryError("XML input must be UTF-8", 1);
|
|
3632
|
-
}
|
|
3633
|
-
return parts2.join("");
|
|
3634
|
-
}
|
|
3635
|
-
async function execute(context, limits) {
|
|
3636
|
-
const budget = new XmlBudget(limits, context.signal);
|
|
3637
|
-
let outputFailed = false;
|
|
3638
|
-
try {
|
|
3639
|
-
const options2 = await argumentsFor(context, budget);
|
|
3640
|
-
const source = await input2(context, options2.file, budget);
|
|
3641
|
-
const parser = parseXmlSteps(source, { ...limits, maxContentNodes: limits.maxNodes, expectedEncoding: "UTF-8" });
|
|
3642
|
-
let parsed = parser.next();
|
|
3643
|
-
try {
|
|
3644
|
-
while (!parsed.done) {
|
|
3645
|
-
await budget.tick(parsed.value);
|
|
3646
|
-
parsed = parser.next();
|
|
3647
|
-
}
|
|
3648
|
-
} finally {
|
|
3649
|
-
if (!parsed.done) parser.return(void 0);
|
|
3650
|
-
}
|
|
3651
|
-
const nodes = await evaluate(options2.query, parsed.value, budget);
|
|
3652
|
-
async function write(part) {
|
|
3653
|
-
for (let offset = 0; offset < part.length; ) {
|
|
3654
|
-
let end = Math.min(offset + 4096, part.length);
|
|
3655
|
-
if (end < part.length && part.charCodeAt(end - 1) >= 55296 && part.charCodeAt(end - 1) <= 56319) end--;
|
|
3656
|
-
await budget.tick(end - offset);
|
|
3657
|
-
const slice = part.slice(offset, end);
|
|
3658
|
-
const size = import_buffer.Buffer.byteLength(slice);
|
|
3659
|
-
if (size > limits.maxOutputBytes - budget.outputBytes) throw new XmlQueryLimitError("maxOutputBytes");
|
|
3660
|
-
budget.outputBytes += size;
|
|
3661
|
-
try {
|
|
3662
|
-
await writeBytes(context.stdout, import_buffer.Buffer.from(slice), context.signal);
|
|
3663
|
-
} catch (error) {
|
|
3664
|
-
outputFailed = true;
|
|
3665
|
-
throw error;
|
|
3666
|
-
}
|
|
3667
|
-
offset = end;
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
if (options2.query.scalar === "count") await write(String(nodes.length));
|
|
3671
|
-
else if (options2.query.scalar === "boolean") await write(nodes.length ? "true" : "false");
|
|
3672
|
-
else if (options2.query.scalar === "string") {
|
|
3673
|
-
for await (const part of stringValue(nodes[0], budget)) await write(part);
|
|
3674
|
-
} else {
|
|
3675
|
-
if (!nodes.length) throw new XmlQueryError("XPath set is empty", 11);
|
|
3676
|
-
for (const node of nodes) {
|
|
3677
|
-
for await (const part of serialize(node, budget)) await write(part);
|
|
3678
|
-
await write("\n");
|
|
3679
|
-
}
|
|
3680
|
-
return { exitCode: 0 };
|
|
3681
|
-
}
|
|
3682
|
-
await write("\n");
|
|
3683
|
-
return { exitCode: 0 };
|
|
3684
|
-
} catch (error) {
|
|
3685
|
-
context.signal.throwIfAborted();
|
|
3686
|
-
if (outputFailed || error instanceof FsError && error.code === "EPIPE") throw error;
|
|
3687
|
-
const status = error instanceof XmlQueryError ? error.status : error instanceof XmlLimitError ? 5 : error instanceof SyntaxError || error instanceof FsError ? 1 : void 0;
|
|
3688
|
-
if (status === void 0) throw error;
|
|
3689
|
-
const message = error instanceof Error ? error.message.slice(0, 1e3) : "XML query failed";
|
|
3690
|
-
await writeDiagnostic(context.stderr, `${context.command}: ${message}
|
|
3691
|
-
`, context.signal);
|
|
3692
|
-
return { exitCode: status };
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
function createXmlCommands(options2 = {}) {
|
|
3696
|
-
const limits = resolveXmlQueryLimits(options2.limits);
|
|
3697
|
-
return ["xq", "xmllint"].map((name) => ({ name, execute: (context) => execute(context, limits) }));
|
|
3698
|
-
}
|
|
3699
|
-
function xmlCommands(options2 = {}) {
|
|
3700
|
-
const definitions = createXmlCommands(options2);
|
|
3701
|
-
const replace = options2.replace ?? false;
|
|
3702
|
-
return { name: "xml-commands", setup(host) {
|
|
3703
|
-
if (!replace) for (const definition of definitions) {
|
|
3704
|
-
if (host.commands.has(definition.name)) throw new Error(`Command already registered: ${definition.name}`);
|
|
3705
|
-
}
|
|
3706
|
-
for (const definition of definitions) host.commands.register(definition, { replace });
|
|
3707
|
-
} };
|
|
3708
|
-
}
|
|
3709
|
-
|
|
3710
3207
|
export {
|
|
3711
3208
|
import_buffer,
|
|
3712
3209
|
init_platform,
|
|
@@ -3779,11 +3276,13 @@ export {
|
|
|
3779
3276
|
emptyInput,
|
|
3780
3277
|
replaceArgument,
|
|
3781
3278
|
escapeBytes,
|
|
3279
|
+
Decimal,
|
|
3782
3280
|
isNumber,
|
|
3783
3281
|
numberValue,
|
|
3784
3282
|
numericToken,
|
|
3785
3283
|
decimalNumber,
|
|
3786
3284
|
compareNumbers,
|
|
3285
|
+
numberText,
|
|
3787
3286
|
defaultJqLimits,
|
|
3788
3287
|
JqError,
|
|
3789
3288
|
JqLimitError,
|
|
@@ -3800,10 +3299,7 @@ export {
|
|
|
3800
3299
|
isObject,
|
|
3801
3300
|
truth,
|
|
3802
3301
|
scalarJson,
|
|
3803
|
-
interruptible
|
|
3804
|
-
defaultXmlQueryLimits,
|
|
3805
|
-
createXmlCommands,
|
|
3806
|
-
xmlCommands
|
|
3302
|
+
interruptible
|
|
3807
3303
|
};
|
|
3808
3304
|
/*! Bundled license information:
|
|
3809
3305
|
|
|
@@ -3818,4 +3314,4 @@ buffer/index.js:
|
|
|
3818
3314
|
* @license MIT
|
|
3819
3315
|
*)
|
|
3820
3316
|
*/
|
|
3821
|
-
//# sourceMappingURL=chunk-
|
|
3317
|
+
//# sourceMappingURL=chunk-B637PJBS.js.map
|