Aktueller Stand

This commit is contained in:
2026-01-23 01:33:35 +01:00
parent 082dc5e110
commit 2766dd12c5
10109 changed files with 1578841 additions and 77685 deletions

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoopSlicedGenerator = void 0;
class NoopSlicedGenerator {
constructor(arb, mrng, biasFactor) {
this.arb = arb;
this.mrng = mrng;
this.biasFactor = biasFactor;
}
attemptExact() {
return;
}
next() {
return this.arb.generate(this.mrng, this.biasFactor);
}
}
exports.NoopSlicedGenerator = NoopSlicedGenerator;

View File

@@ -0,0 +1,196 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchedulerImplem = void 0;
const TextEscaper_1 = require("../helpers/TextEscaper");
const symbols_1 = require("../../../check/symbols");
const stringify_1 = require("../../../utils/stringify");
const defaultSchedulerAct = (f) => f();
class SchedulerImplem {
constructor(act, taskSelector) {
this.act = act;
this.taskSelector = taskSelector;
this.lastTaskId = 0;
this.sourceTaskSelector = taskSelector.clone();
this.scheduledTasks = [];
this.triggeredTasks = [];
this.scheduledWatchers = [];
}
static buildLog(reportItem) {
return `[task\${${reportItem.taskId}}] ${reportItem.label.length !== 0 ? `${reportItem.schedulingType}::${reportItem.label}` : reportItem.schedulingType} ${reportItem.status}${reportItem.outputValue !== undefined ? ` with value ${(0, TextEscaper_1.escapeForTemplateString)(reportItem.outputValue)}` : ''}`;
}
log(schedulingType, taskId, label, metadata, status, data) {
this.triggeredTasks.push({
status,
schedulingType,
taskId,
label,
metadata,
outputValue: data !== undefined ? (0, stringify_1.stringify)(data) : undefined,
});
}
scheduleInternal(schedulingType, label, task, metadata, customAct, thenTaskToBeAwaited) {
let trigger = null;
const taskId = ++this.lastTaskId;
const scheduledPromise = new Promise((resolve, reject) => {
trigger = () => {
(thenTaskToBeAwaited ? task.then(() => thenTaskToBeAwaited()) : task).then((data) => {
this.log(schedulingType, taskId, label, metadata, 'resolved', data);
return resolve(data);
}, (err) => {
this.log(schedulingType, taskId, label, metadata, 'rejected', err);
return reject(err);
});
};
});
this.scheduledTasks.push({
original: task,
scheduled: scheduledPromise,
trigger: trigger,
schedulingType,
taskId,
label,
metadata,
customAct,
});
if (this.scheduledWatchers.length !== 0) {
this.scheduledWatchers[0]();
}
return scheduledPromise;
}
schedule(task, label, metadata, customAct) {
return this.scheduleInternal('promise', label || '', task, metadata, customAct || defaultSchedulerAct);
}
scheduleFunction(asyncFunction, customAct) {
return (...args) => this.scheduleInternal('function', `${asyncFunction.name}(${args.map(stringify_1.stringify).join(',')})`, asyncFunction(...args), undefined, customAct || defaultSchedulerAct);
}
scheduleSequence(sequenceBuilders, customAct) {
const status = { done: false, faulty: false };
const dummyResolvedPromise = { then: (f) => f() };
let resolveSequenceTask = () => { };
const sequenceTask = new Promise((resolve) => (resolveSequenceTask = resolve));
sequenceBuilders
.reduce((previouslyScheduled, item) => {
const [builder, label, metadata] = typeof item === 'function' ? [item, item.name, undefined] : [item.builder, item.label, item.metadata];
return previouslyScheduled.then(() => {
const scheduled = this.scheduleInternal('sequence', label, dummyResolvedPromise, metadata, customAct || defaultSchedulerAct, () => builder());
scheduled.catch(() => {
status.faulty = true;
resolveSequenceTask();
});
return scheduled;
});
}, dummyResolvedPromise)
.then(() => {
status.done = true;
resolveSequenceTask();
}, () => {
});
return Object.assign(status, {
task: Promise.resolve(sequenceTask).then(() => {
return { done: status.done, faulty: status.faulty };
}),
});
}
count() {
return this.scheduledTasks.length;
}
internalWaitOne() {
if (this.scheduledTasks.length === 0) {
throw new Error('No task scheduled');
}
const taskIndex = this.taskSelector.nextTaskIndex(this.scheduledTasks);
const [scheduledTask] = this.scheduledTasks.splice(taskIndex, 1);
return scheduledTask.customAct(async () => {
scheduledTask.trigger();
try {
await scheduledTask.scheduled;
}
catch (_err) {
}
});
}
async waitOne(customAct) {
const waitAct = customAct || defaultSchedulerAct;
await this.act(() => waitAct(async () => await this.internalWaitOne()));
}
async waitAll(customAct) {
while (this.scheduledTasks.length > 0) {
await this.waitOne(customAct);
}
}
async waitFor(unscheduledTask, customAct) {
let taskResolved = false;
let awaiterPromise = null;
const awaiter = async () => {
while (!taskResolved && this.scheduledTasks.length > 0) {
await this.waitOne(customAct);
}
awaiterPromise = null;
};
const handleNotified = () => {
if (awaiterPromise !== null) {
return;
}
awaiterPromise = Promise.resolve().then(awaiter);
};
const clearAndReplaceWatcher = () => {
const handleNotifiedIndex = this.scheduledWatchers.indexOf(handleNotified);
if (handleNotifiedIndex !== -1) {
this.scheduledWatchers.splice(handleNotifiedIndex, 1);
}
if (handleNotifiedIndex === 0 && this.scheduledWatchers.length !== 0) {
this.scheduledWatchers[0]();
}
};
const rewrappedTask = unscheduledTask.then((ret) => {
taskResolved = true;
if (awaiterPromise === null) {
clearAndReplaceWatcher();
return ret;
}
return awaiterPromise.then(() => {
clearAndReplaceWatcher();
return ret;
});
}, (err) => {
taskResolved = true;
if (awaiterPromise === null) {
clearAndReplaceWatcher();
throw err;
}
return awaiterPromise.then(() => {
clearAndReplaceWatcher();
throw err;
});
});
if (this.scheduledTasks.length > 0 && this.scheduledWatchers.length === 0) {
handleNotified();
}
this.scheduledWatchers.push(handleNotified);
return rewrappedTask;
}
report() {
return [
...this.triggeredTasks,
...this.scheduledTasks.map((t) => ({
status: 'pending',
schedulingType: t.schedulingType,
taskId: t.taskId,
label: t.label,
metadata: t.metadata,
})),
];
}
toString() {
return ('schedulerFor()`\n' +
this.report()
.map(SchedulerImplem.buildLog)
.map((log) => `-> ${log}`)
.join('\n') +
'`');
}
[symbols_1.cloneMethod]() {
return new SchedulerImplem(this.act, this.sourceTaskSelector);
}
}
exports.SchedulerImplem = SchedulerImplem;

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlicedBasedGenerator = void 0;
const Value_1 = require("../../../check/arbitrary/definition/Value");
const globals_1 = require("../../../utils/globals");
const safeMathMin = Math.min;
const safeMathMax = Math.max;
class SlicedBasedGenerator {
constructor(arb, mrng, slices, biasFactor) {
this.arb = arb;
this.mrng = mrng;
this.slices = slices;
this.biasFactor = biasFactor;
this.activeSliceIndex = 0;
this.nextIndexInSlice = 0;
this.lastIndexInSlice = -1;
}
attemptExact(targetLength) {
if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) {
const eligibleIndices = [];
for (let index = 0; index !== this.slices.length; ++index) {
const slice = this.slices[index];
if (slice.length === targetLength) {
(0, globals_1.safePush)(eligibleIndices, index);
}
}
if (eligibleIndices.length === 0) {
return;
}
this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)];
this.nextIndexInSlice = 0;
this.lastIndexInSlice = targetLength - 1;
}
}
next() {
if (this.nextIndexInSlice <= this.lastIndexInSlice) {
return new Value_1.Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined);
}
if (this.mrng.nextInt(1, this.biasFactor) !== 1) {
return this.arb.generate(this.mrng, this.biasFactor);
}
this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1);
const slice = this.slices[this.activeSliceIndex];
if (this.mrng.nextInt(1, this.biasFactor) !== 1) {
this.nextIndexInSlice = 1;
this.lastIndexInSlice = slice.length - 1;
return new Value_1.Value(slice[0], undefined);
}
const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1);
const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1);
this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB);
this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB);
return new Value_1.Value(slice[this.nextIndexInSlice++], undefined);
}
}
exports.SlicedBasedGenerator = SlicedBasedGenerator;