@poe-platform/safe-bash 0.1.435 → 0.1.438
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/browser.js +114 -23
- package/dist/safe-bash/browser.js.map +3 -3
- package/dist/safe-bash/portable.js +114 -23
- package/dist/safe-bash/portable.js.map +3 -3
- package/dist/safe-bash/shell/arrays/state.d.ts +6 -1
- package/dist/safe-bash/shell/arrays/state.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/state.js +22 -1
- package/dist/safe-bash/shell/arrays/state.js.map +1 -1
- package/dist/safe-bash/shell/getopts.d.ts +10 -1
- package/dist/safe-bash/shell/getopts.d.ts.map +1 -1
- package/dist/safe-bash/shell/getopts.js +55 -6
- package/dist/safe-bash/shell/getopts.js.map +1 -1
- package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
- package/dist/safe-bash/shell/runtime.js +48 -21
- package/dist/safe-bash/shell/runtime.js.map +1 -1
- package/package.json +2 -2
|
@@ -9314,6 +9314,39 @@ function throwCleanupFailures(failures) {
|
|
|
9314
9314
|
|
|
9315
9315
|
// packages/safe-bash/src/shell/getopts.ts
|
|
9316
9316
|
init_platform();
|
|
9317
|
+
var ownedInputs = /* @__PURE__ */ new WeakMap();
|
|
9318
|
+
function getoptsInputAllocationSize(argumentsCount) {
|
|
9319
|
+
return { bytes: 256 + argumentsCount * 8, slots: argumentsCount + 2 };
|
|
9320
|
+
}
|
|
9321
|
+
async function createGetoptsInput(args, allocation, controls2) {
|
|
9322
|
+
const work = new ScanWork(controls2);
|
|
9323
|
+
if (!Array.isArray(args)) throw new GetoptsError("INVALID_INPUT", "Getopts requires an argument array");
|
|
9324
|
+
const length = args.length;
|
|
9325
|
+
if (length > work.maxArguments) throw new GetoptsError("ARGUMENT_LIMIT", "Getopts argument limit exceeded");
|
|
9326
|
+
const size = getoptsInputAllocationSize(length);
|
|
9327
|
+
const reservation = allocation?.reserve(size.bytes, size.slots);
|
|
9328
|
+
try {
|
|
9329
|
+
const snapshot = [];
|
|
9330
|
+
for (let index = 0; index < length; index++) {
|
|
9331
|
+
const waiting = work.step();
|
|
9332
|
+
if (waiting) await waiting;
|
|
9333
|
+
snapshot.push(args[index]);
|
|
9334
|
+
}
|
|
9335
|
+
await work.flush();
|
|
9336
|
+
if (args.length !== length) throw new GetoptsError("INVALID_INPUT", "Getopts argument extent changed during admission");
|
|
9337
|
+
const input3 = Object.freeze({ args: Object.freeze(snapshot) });
|
|
9338
|
+
reservation?.commit(input3);
|
|
9339
|
+
ownedInputs.set(input3, {});
|
|
9340
|
+
return input3;
|
|
9341
|
+
} catch (error) {
|
|
9342
|
+
try {
|
|
9343
|
+
reservation?.release();
|
|
9344
|
+
} catch (cleanup) {
|
|
9345
|
+
throw new AggregateError([error, cleanup], "Getopts input allocation and release failed");
|
|
9346
|
+
}
|
|
9347
|
+
throw error;
|
|
9348
|
+
}
|
|
9349
|
+
}
|
|
9317
9350
|
var GetoptsError = class extends Error {
|
|
9318
9351
|
constructor(code, message2) {
|
|
9319
9352
|
super(message2);
|
|
@@ -9378,6 +9411,9 @@ var ScanWork = class {
|
|
|
9378
9411
|
check() {
|
|
9379
9412
|
this.signal?.throwIfAborted();
|
|
9380
9413
|
}
|
|
9414
|
+
get inputBytes() {
|
|
9415
|
+
return this.bytes;
|
|
9416
|
+
}
|
|
9381
9417
|
step() {
|
|
9382
9418
|
this.check();
|
|
9383
9419
|
if (this.steps === this.maxSteps) throw new GetoptsError("STEP_LIMIT", "Getopts work step limit exceeded");
|
|
@@ -9434,19 +9470,25 @@ async function validateString(value2, work, optstring = false) {
|
|
|
9434
9470
|
else work.addBytes(3);
|
|
9435
9471
|
}
|
|
9436
9472
|
}
|
|
9437
|
-
async function scanGetopts(state, optstring,
|
|
9473
|
+
async function scanGetopts(state, optstring, input3, options3) {
|
|
9438
9474
|
if (!record2(options3) || typeof options3.reportErrors !== "boolean") throw new GetoptsError("INVALID_INPUT", "Getopts requires explicit diagnostic policy and work controls");
|
|
9439
9475
|
const work = new ScanWork(options3.work);
|
|
9440
9476
|
const original = cloneGetoptsState(state);
|
|
9477
|
+
const owned = ownedInputs.get(input3);
|
|
9478
|
+
const args = owned ? input3.args : input3;
|
|
9441
9479
|
if (!Array.isArray(args)) throw new GetoptsError("INVALID_INPUT", "Getopts requires an argument array");
|
|
9442
9480
|
if (args.length > work.maxArguments) throw new GetoptsError("ARGUMENT_LIMIT", "Getopts argument limit exceeded");
|
|
9443
9481
|
const starting = work.step();
|
|
9444
9482
|
if (starting) await starting;
|
|
9445
9483
|
await validateString(optstring, work, true);
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9484
|
+
const specificationBytes = work.inputBytes;
|
|
9485
|
+
if (owned?.bytes !== void 0) work.addBytes(owned.bytes);
|
|
9486
|
+
else {
|
|
9487
|
+
for (let argument = 0; argument < args.length; argument++) {
|
|
9488
|
+
const waiting = work.step();
|
|
9489
|
+
if (waiting) await waiting;
|
|
9490
|
+
await validateString(args[argument], work);
|
|
9491
|
+
}
|
|
9450
9492
|
}
|
|
9451
9493
|
const silent = optstring.startsWith(":");
|
|
9452
9494
|
const specification = new Int8Array(128).fill(-1);
|
|
@@ -9462,6 +9504,7 @@ async function scanGetopts(state, optstring, args, options3) {
|
|
|
9462
9504
|
const waiting = work.step();
|
|
9463
9505
|
if (waiting) await waiting;
|
|
9464
9506
|
await work.flush();
|
|
9507
|
+
if (owned) owned.bytes = work.inputBytes - specificationBytes;
|
|
9465
9508
|
return { state: active === void 0 ? { index } : { index, active: { ...active } }, kind, status: kind === "end" ? 1 : 0, option: option2, optind: index, argument, diagnostic: diagnostic3 };
|
|
9466
9509
|
};
|
|
9467
9510
|
const end = () => {
|
|
@@ -10629,20 +10672,45 @@ var StateMonitor = class {
|
|
|
10629
10672
|
#restorations;
|
|
10630
10673
|
#overlays;
|
|
10631
10674
|
#retireCleanup;
|
|
10675
|
+
#positionalRevision = {};
|
|
10676
|
+
#getoptsInput;
|
|
10632
10677
|
closeValues() {
|
|
10633
10678
|
this.values.close();
|
|
10634
10679
|
this.positionals.close();
|
|
10680
|
+
this.invalidateGetoptsInput();
|
|
10635
10681
|
this.#retireCleanup?.();
|
|
10636
10682
|
this.#retireCleanup = void 0;
|
|
10637
10683
|
}
|
|
10684
|
+
get positionalRevision() {
|
|
10685
|
+
return this.#positionalRevision;
|
|
10686
|
+
}
|
|
10687
|
+
get getoptsInput() {
|
|
10688
|
+
return this.#getoptsInput?.input;
|
|
10689
|
+
}
|
|
10690
|
+
retainGetoptsInput(revision, input3, allocation) {
|
|
10691
|
+
this.session.scope.assertOpen();
|
|
10692
|
+
if (revision !== this.#positionalRevision) return false;
|
|
10693
|
+
this.#getoptsInput?.allocation.close();
|
|
10694
|
+
this.#getoptsInput = { input: input3, allocation };
|
|
10695
|
+
return true;
|
|
10696
|
+
}
|
|
10697
|
+
invalidateGetoptsInput() {
|
|
10698
|
+
this.#getoptsInput?.allocation.close();
|
|
10699
|
+
this.#getoptsInput = void 0;
|
|
10700
|
+
this.#positionalRevision = {};
|
|
10701
|
+
}
|
|
10638
10702
|
changedValue(target, field, key) {
|
|
10639
10703
|
if (field === "state") {
|
|
10640
10704
|
if (key === "variables") this.values.invalidate();
|
|
10641
|
-
if (key === "positional")
|
|
10705
|
+
if (key === "positional") {
|
|
10706
|
+
this.positionals.invalidate();
|
|
10707
|
+
this.invalidateGetoptsInput();
|
|
10708
|
+
}
|
|
10642
10709
|
} else if (field === "variables" && (this.raw.variables === target || this.raw.variables === this.#wrapped.get(target))) {
|
|
10643
10710
|
this.values.invalidate(String(key));
|
|
10644
10711
|
} else if (field === "positional" && (this.raw.positional === target || this.raw.positional === this.#wrapped.get(target))) {
|
|
10645
10712
|
this.positionals.invalidate();
|
|
10713
|
+
this.invalidateGetoptsInput();
|
|
10646
10714
|
}
|
|
10647
10715
|
}
|
|
10648
10716
|
internalOwner() {
|
|
@@ -15517,26 +15585,49 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
|
|
|
15517
15585
|
}
|
|
15518
15586
|
const optstring = context.args[offset];
|
|
15519
15587
|
const name2 = context.args[offset + 1];
|
|
15520
|
-
const
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
|
|
15526
|
-
|
|
15527
|
-
const
|
|
15528
|
-
|
|
15529
|
-
|
|
15588
|
+
const explicit = context.args.length > offset + 2;
|
|
15589
|
+
const monitor = explicit ? void 0 : stateMonitor(state);
|
|
15590
|
+
const revision = monitor?.positionalRevision;
|
|
15591
|
+
const supplied = explicit ? context.args.slice(offset + 2) : state.positional;
|
|
15592
|
+
if (supplied.length > fields) this.budget.fail("maxExpansionFields");
|
|
15593
|
+
const maxBytes = saturatedProduct(bytes2, saturatedSum(supplied.length, 1));
|
|
15594
|
+
const maxSteps = saturatedSum(saturatedProduct(maxBytes, 2), saturatedSum(supplied.length, 2));
|
|
15595
|
+
const work = { maxArguments: fields, maxBytes, maxSteps, yieldEvery: 128, signal: this.signal, checkpoint };
|
|
15596
|
+
let input3 = monitor?.getoptsInput;
|
|
15597
|
+
let allocation;
|
|
15530
15598
|
let result;
|
|
15531
15599
|
try {
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15600
|
+
if (!input3 && monitor) {
|
|
15601
|
+
const size = getoptsInputAllocationSize(supplied.length);
|
|
15602
|
+
const arena = this.budget.values;
|
|
15603
|
+
const usage = arena.usage;
|
|
15604
|
+
if (size.bytes + 64 <= arena.maximumBytes - usage.bytes && size.slots + 1 <= arena.maximumSlots - usage.slots) {
|
|
15605
|
+
allocation = arena.scope();
|
|
15606
|
+
input3 = await createGetoptsInput(supplied, allocation, work);
|
|
15607
|
+
}
|
|
15608
|
+
}
|
|
15609
|
+
const args = input3?.args ?? supplied;
|
|
15610
|
+
if (!input3 || allocation) for (let index = 0; index < args.length; index++) {
|
|
15611
|
+
this.signal.throwIfAborted();
|
|
15612
|
+
admit2(args[index]);
|
|
15613
|
+
if ((index + 1) % 128 === 0) await checkpoint();
|
|
15614
|
+
}
|
|
15615
|
+
state.getopts ??= cloneGetoptsBinding(state);
|
|
15616
|
+
try {
|
|
15617
|
+
result = await scanGetopts(state.getopts.cursor, optstring, input3 ?? args, {
|
|
15618
|
+
reportErrors: state.variables.OPTERR === void 0 || state.variables.OPTERR === "" || decimalIndex(state.variables.OPTERR) !== 0,
|
|
15619
|
+
work
|
|
15620
|
+
});
|
|
15621
|
+
} catch (error) {
|
|
15622
|
+
this.signal.throwIfAborted();
|
|
15623
|
+
if (error instanceof GetoptsError && (error.code === "NON_ASCII_OPTION" || error.code === "INVALID_INPUT")) throw new CommandFailure(`getopts: ${error.message}`, 2);
|
|
15624
|
+
throw error;
|
|
15625
|
+
}
|
|
15537
15626
|
this.signal.throwIfAborted();
|
|
15538
|
-
if (
|
|
15539
|
-
|
|
15627
|
+
if (monitor && monitor.positionalRevision !== revision) throw new CommandFailure("getopts: positional arguments changed during validation", 2);
|
|
15628
|
+
if (allocation && monitor.retainGetoptsInput(revision, input3, allocation)) allocation = void 0;
|
|
15629
|
+
} finally {
|
|
15630
|
+
allocation?.close();
|
|
15540
15631
|
}
|
|
15541
15632
|
this.signal.throwIfAborted();
|
|
15542
15633
|
state.getopts.cursor = result.state;
|