@poe-platform/safe-bash 0.1.81 → 0.1.83
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 +131 -65
- package/dist/safe-bash/browser.js.map +4 -4
- package/dist/safe-bash/commands/internal.d.ts +1 -1
- package/dist/safe-bash/commands/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/internal.js +18 -25
- package/dist/safe-bash/commands/internal.js.map +1 -1
- package/dist/safe-bash/commands/record-buffer.d.ts +11 -0
- package/dist/safe-bash/commands/record-buffer.d.ts.map +1 -0
- package/dist/safe-bash/commands/record-buffer.js +61 -0
- package/dist/safe-bash/commands/record-buffer.js.map +1 -0
- package/dist/safe-bash/commands/sort-admission.d.ts +6 -0
- package/dist/safe-bash/commands/sort-admission.d.ts.map +1 -0
- package/dist/safe-bash/commands/sort-admission.js +16 -0
- package/dist/safe-bash/commands/sort-admission.js.map +1 -0
- package/dist/safe-bash/commands/text.d.ts.map +1 -1
- package/dist/safe-bash/commands/text.js +41 -49
- package/dist/safe-bash/commands/text.js.map +1 -1
- package/package.json +2 -2
|
@@ -2623,6 +2623,69 @@ var predicateRequirements = [
|
|
|
2623
2623
|
{ id: "access", description: "Inspect path access permissions", capabilities: ["access"] }
|
|
2624
2624
|
];
|
|
2625
2625
|
|
|
2626
|
+
// packages/safe-bash/src/commands/record-buffer.ts
|
|
2627
|
+
init_platform();
|
|
2628
|
+
var segmentSize = 4096;
|
|
2629
|
+
var RecordBuffer = class {
|
|
2630
|
+
constructor(capacity, finalizationCapacity = capacity * 2) {
|
|
2631
|
+
this.capacity = capacity;
|
|
2632
|
+
this.finalizationCapacity = finalizationCapacity;
|
|
2633
|
+
}
|
|
2634
|
+
capacity;
|
|
2635
|
+
finalizationCapacity;
|
|
2636
|
+
#segments = [];
|
|
2637
|
+
#size = 0;
|
|
2638
|
+
#allocated = 0;
|
|
2639
|
+
get size() {
|
|
2640
|
+
return this.#size;
|
|
2641
|
+
}
|
|
2642
|
+
#admit(length) {
|
|
2643
|
+
if (length > this.capacity - this.#size) {
|
|
2644
|
+
throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
append(bytes2, start = 0, end = bytes2.length) {
|
|
2648
|
+
this.#admit(end - start);
|
|
2649
|
+
let offset = start;
|
|
2650
|
+
while (offset < end) {
|
|
2651
|
+
let segment = this.#segments.at(-1);
|
|
2652
|
+
const used = this.#size % segmentSize;
|
|
2653
|
+
if (!segment || used === 0) {
|
|
2654
|
+
segment = new Uint8Array(Math.min(segmentSize, this.capacity - this.#allocated));
|
|
2655
|
+
this.#segments.push(segment);
|
|
2656
|
+
this.#allocated += segment.length;
|
|
2657
|
+
}
|
|
2658
|
+
const length = Math.min(end - offset, segment.length - used);
|
|
2659
|
+
segment.set(bytes2.subarray(offset, offset + length), used);
|
|
2660
|
+
this.#size += length;
|
|
2661
|
+
offset += length;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
finish(admit2, bytes2, start = 0, end = bytes2?.length ?? 0) {
|
|
2665
|
+
this.#admit(end - start);
|
|
2666
|
+
const size = this.#size + end - start;
|
|
2667
|
+
admit2?.(size);
|
|
2668
|
+
if (size > this.finalizationCapacity - this.#allocated) {
|
|
2669
|
+
throw new FsError("EFBIG", { message: "line finalization buffer limit exceeded" });
|
|
2670
|
+
}
|
|
2671
|
+
const result = new Uint8Array(size);
|
|
2672
|
+
let offset = 0;
|
|
2673
|
+
for (const segment of this.#segments) {
|
|
2674
|
+
const length = Math.min(segment.length, this.#size - offset);
|
|
2675
|
+
result.set(segment.subarray(0, length), offset);
|
|
2676
|
+
offset += length;
|
|
2677
|
+
}
|
|
2678
|
+
if (bytes2 && end > start) result.set(bytes2.subarray(start, end), offset);
|
|
2679
|
+
this.clear();
|
|
2680
|
+
return result;
|
|
2681
|
+
}
|
|
2682
|
+
clear() {
|
|
2683
|
+
this.#segments = [];
|
|
2684
|
+
this.#size = 0;
|
|
2685
|
+
this.#allocated = 0;
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2626
2689
|
// packages/safe-bash/src/commands/internal.ts
|
|
2627
2690
|
var encoder2 = new TextEncoder();
|
|
2628
2691
|
var decoder2 = new TextDecoder();
|
|
@@ -2796,29 +2859,22 @@ function concatenate(chunks, size = chunks.reduce((sum, chunk) => sum + chunk.le
|
|
|
2796
2859
|
}
|
|
2797
2860
|
return result;
|
|
2798
2861
|
}
|
|
2799
|
-
async function* lines(source, separator = 10) {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
pending.
|
|
2810
|
-
yield { bytes: concatenate(pending, size), terminated: true };
|
|
2811
|
-
pending = [];
|
|
2812
|
-
size = 0;
|
|
2813
|
-
start = offset + 1;
|
|
2814
|
-
}
|
|
2815
|
-
if (start < chunk.length) {
|
|
2816
|
-
pending.push(new Uint8Array(chunk.subarray(start)));
|
|
2817
|
-
size += chunk.length - start;
|
|
2818
|
-
if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
2862
|
+
async function* lines(source, separator = 10, admit2) {
|
|
2863
|
+
const pending = new RecordBuffer(bufferLimit);
|
|
2864
|
+
try {
|
|
2865
|
+
for await (const chunk of source) {
|
|
2866
|
+
let start = 0;
|
|
2867
|
+
for (let offset = 0; offset < chunk.length; offset++) {
|
|
2868
|
+
if (chunk[offset] !== separator) continue;
|
|
2869
|
+
yield { bytes: pending.finish(admit2, chunk, start, offset), terminated: true };
|
|
2870
|
+
start = offset + 1;
|
|
2871
|
+
}
|
|
2872
|
+
pending.append(chunk, start);
|
|
2819
2873
|
}
|
|
2874
|
+
if (pending.size) yield { bytes: pending.finish(admit2), terminated: false };
|
|
2875
|
+
} finally {
|
|
2876
|
+
pending.clear();
|
|
2820
2877
|
}
|
|
2821
|
-
if (size) yield { bytes: concatenate(pending, size), terminated: false };
|
|
2822
2878
|
}
|
|
2823
2879
|
function emptyInput() {
|
|
2824
2880
|
return toByteSource("");
|
|
@@ -4653,6 +4709,23 @@ function streamCommands() {
|
|
|
4653
4709
|
|
|
4654
4710
|
// packages/safe-bash/src/commands/text.ts
|
|
4655
4711
|
init_platform();
|
|
4712
|
+
|
|
4713
|
+
// packages/safe-bash/src/commands/sort-admission.ts
|
|
4714
|
+
init_platform();
|
|
4715
|
+
var SortRecordBudget = class {
|
|
4716
|
+
#records = 0;
|
|
4717
|
+
#bytes = 0;
|
|
4718
|
+
admit(byteLength2) {
|
|
4719
|
+
const bytes2 = byteLength2 + 1;
|
|
4720
|
+
if (this.#records >= 1e5 || bytes2 > bufferLimit - this.#bytes) {
|
|
4721
|
+
throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
|
|
4722
|
+
}
|
|
4723
|
+
this.#records++;
|
|
4724
|
+
this.#bytes += bytes2;
|
|
4725
|
+
}
|
|
4726
|
+
};
|
|
4727
|
+
|
|
4728
|
+
// packages/safe-bash/src/commands/text.ts
|
|
4656
4729
|
var SortWork = class {
|
|
4657
4730
|
constructor(signal) {
|
|
4658
4731
|
this.signal = signal;
|
|
@@ -4921,31 +4994,28 @@ async function emitRecords(context, records, destination) {
|
|
|
4921
4994
|
await context.fs.writeFile(pathOf(context, destination), concatenate(chunks, size), { signal: context.signal });
|
|
4922
4995
|
}
|
|
4923
4996
|
}
|
|
4924
|
-
async function collectSortRecords(source, delimiter, accept) {
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
pending.
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
}
|
|
4947
|
-
}
|
|
4948
|
-
if (size) accept(concatenate(pending, size));
|
|
4997
|
+
async function collectSortRecords(source, delimiter, budget, signal, accept) {
|
|
4998
|
+
const pending = new RecordBuffer(bufferLimit);
|
|
4999
|
+
const admit2 = (length) => {
|
|
5000
|
+
signal.throwIfAborted();
|
|
5001
|
+
budget.admit(length);
|
|
5002
|
+
};
|
|
5003
|
+
try {
|
|
5004
|
+
for await (const chunk of source) {
|
|
5005
|
+
let start = 0;
|
|
5006
|
+
for (let offset = 0; offset < chunk.length; offset++) {
|
|
5007
|
+
if (chunk[offset] !== delimiter) continue;
|
|
5008
|
+
const accepted = accept(pending.finish(admit2, chunk, start, offset));
|
|
5009
|
+
if ((accepted instanceof Promise ? await accepted : accepted) === false) return false;
|
|
5010
|
+
start = offset + 1;
|
|
5011
|
+
}
|
|
5012
|
+
pending.append(chunk, start);
|
|
5013
|
+
}
|
|
5014
|
+
if (pending.size) return await accept(pending.finish(admit2)) !== false;
|
|
5015
|
+
return true;
|
|
5016
|
+
} finally {
|
|
5017
|
+
pending.clear();
|
|
5018
|
+
}
|
|
4949
5019
|
}
|
|
4950
5020
|
function textCommands() {
|
|
4951
5021
|
return [
|
|
@@ -5037,30 +5107,26 @@ function textCommands() {
|
|
|
5037
5107
|
return result || (simple || parsed.flags.has("s") || parsed.flags.has("u") ? 0 : await compareSortBytes(left, right, work) * direction);
|
|
5038
5108
|
};
|
|
5039
5109
|
const records = [];
|
|
5040
|
-
|
|
5110
|
+
const recordBudget = new SortRecordBudget();
|
|
5041
5111
|
const exitCode = 0;
|
|
5042
5112
|
const delimiter = parsed.flags.has("z") ? 0 : 10;
|
|
5043
5113
|
for (const name2 of parsed.operands.length ? parsed.operands : ["-"]) {
|
|
5044
5114
|
try {
|
|
5045
|
-
|
|
5046
|
-
await collectSortRecords(input(context, name2), delimiter, (bytes2) => {
|
|
5047
|
-
context.signal.throwIfAborted();
|
|
5048
|
-
size += bytes2.length + 1;
|
|
5049
|
-
if (size > bufferLimit) throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
|
|
5050
|
-
records.push(bytes2);
|
|
5051
|
-
});
|
|
5052
|
-
continue;
|
|
5053
|
-
}
|
|
5054
|
-
for await (const line of lines(input(context, name2), delimiter)) {
|
|
5115
|
+
const complete2 = await collectSortRecords(input(context, name2), delimiter, recordBudget, context.signal, (bytes2) => {
|
|
5055
5116
|
context.signal.throwIfAborted();
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
|
|
5060
|
-
return { exitCode: 1 };
|
|
5117
|
+
if (!parsed.flags.has("c")) {
|
|
5118
|
+
records.push(bytes2);
|
|
5119
|
+
return;
|
|
5061
5120
|
}
|
|
5062
|
-
|
|
5063
|
-
|
|
5121
|
+
return (async () => {
|
|
5122
|
+
if (records.length && (await compare(records.at(-1), bytes2) > 0 || parsed.flags.has("u") && await keyCompare(records.at(-1), bytes2) === 0)) {
|
|
5123
|
+
await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
|
|
5124
|
+
return false;
|
|
5125
|
+
}
|
|
5126
|
+
records.push(bytes2);
|
|
5127
|
+
})();
|
|
5128
|
+
});
|
|
5129
|
+
if (!complete2) return { exitCode: 1 };
|
|
5064
5130
|
} catch (error) {
|
|
5065
5131
|
await diagnostic(context, error);
|
|
5066
5132
|
return { exitCode: 2 };
|
|
@@ -5215,7 +5281,7 @@ function textCommands() {
|
|
|
5215
5281
|
if (start >= 0) await writer.write(line.bytes.subarray(start, end));
|
|
5216
5282
|
}
|
|
5217
5283
|
} else {
|
|
5218
|
-
const decoder3 = new TextDecoder();
|
|
5284
|
+
const decoder3 = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
5219
5285
|
let index = 0;
|
|
5220
5286
|
let emitted = false;
|
|
5221
5287
|
let previousIncluded = false;
|