Добавлена ДБ

This commit is contained in:
Georgiy Syralev
2025-09-15 18:10:26 +03:00
parent 253ad8c19b
commit c954b5268e
5824 changed files with 1107594 additions and 19141 deletions

501
node_modules/effect/dist/esm/internal/stm/core.js generated vendored Normal file
View File

@@ -0,0 +1,501 @@
import * as Cause from "../../Cause.js";
import * as Context from "../../Context.js";
import * as Effect from "../../Effect.js";
import * as Either from "../../Either.js";
import * as Equal from "../../Equal.js";
import * as Exit from "../../Exit.js";
import * as FiberRef from "../../FiberRef.js";
import { constVoid, dual, pipe } from "../../Function.js";
import * as Hash from "../../Hash.js";
import { pipeArguments } from "../../Pipeable.js";
import { hasProperty } from "../../Predicate.js";
import { internalCall, YieldWrap } from "../../Utils.js";
import { ChannelTypeId } from "../core-stream.js";
import { withFiberRuntime } from "../core.js";
import { effectVariance, StreamTypeId } from "../effectable.js";
import { OP_COMMIT } from "../opCodes/effect.js";
import { SingleShotGen } from "../singleShotGen.js";
import { SinkTypeId } from "../sink.js";
import * as Journal from "./journal.js";
import * as OpCodes from "./opCodes/stm.js";
import * as TExitOpCodes from "./opCodes/tExit.js";
import * as TryCommitOpCodes from "./opCodes/tryCommit.js";
import * as STMState from "./stmState.js";
import * as TExit from "./tExit.js";
import * as TryCommit from "./tryCommit.js";
import * as TxnId from "./txnId.js";
/** @internal */
const STMSymbolKey = "effect/STM";
/** @internal */
export const STMTypeId = /*#__PURE__*/Symbol.for(STMSymbolKey);
const stmVariance = {
/* c8 ignore next */
_R: _ => _,
/* c8 ignore next */
_E: _ => _,
/* c8 ignore next */
_A: _ => _
};
/** @internal */
class STMPrimitive {
effect_instruction_i0;
_op = OP_COMMIT;
effect_instruction_i1 = undefined;
effect_instruction_i2 = undefined;
[Effect.EffectTypeId];
[StreamTypeId];
[SinkTypeId];
[ChannelTypeId];
get [STMTypeId]() {
return stmVariance;
}
constructor(effect_instruction_i0) {
this.effect_instruction_i0 = effect_instruction_i0;
this[Effect.EffectTypeId] = effectVariance;
this[StreamTypeId] = stmVariance;
this[SinkTypeId] = stmVariance;
this[ChannelTypeId] = stmVariance;
}
[Equal.symbol](that) {
return this === that;
}
[Hash.symbol]() {
return Hash.cached(this, Hash.random(this));
}
[Symbol.iterator]() {
return new SingleShotGen(new YieldWrap(this));
}
commit() {
return unsafeAtomically(this, constVoid, constVoid);
}
pipe() {
return pipeArguments(this, arguments);
}
}
/** @internal */
export const isSTM = u => hasProperty(u, STMTypeId);
/** @internal */
export const commit = self => unsafeAtomically(self, constVoid, constVoid);
/** @internal */
export const unsafeAtomically = (self, onDone, onInterrupt) => withFiberRuntime(state => {
const fiberId = state.id();
const env = state.getFiberRef(FiberRef.currentContext);
const scheduler = state.getFiberRef(FiberRef.currentScheduler);
const priority = state.getFiberRef(FiberRef.currentSchedulingPriority);
const commitResult = tryCommitSync(fiberId, self, env, scheduler, priority);
switch (commitResult._tag) {
case TryCommitOpCodes.OP_DONE:
{
onDone(commitResult.exit);
return commitResult.exit;
}
case TryCommitOpCodes.OP_SUSPEND:
{
const txnId = TxnId.make();
const state = {
value: STMState.running
};
const effect = Effect.async(k => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, priority, k));
return Effect.uninterruptibleMask(restore => pipe(restore(effect), Effect.catchAllCause(cause => {
let currentState = state.value;
if (STMState.isRunning(currentState)) {
state.value = STMState.interrupted;
}
currentState = state.value;
if (STMState.isDone(currentState)) {
onDone(currentState.exit);
return currentState.exit;
}
onInterrupt();
return Effect.failCause(cause);
})));
}
}
});
/** @internal */
const tryCommit = (fiberId, stm, state, env, scheduler, priority) => {
const journal = new Map();
const tExit = new STMDriver(stm, journal, fiberId, env).run();
const analysis = Journal.analyzeJournal(journal);
if (analysis === Journal.JournalAnalysisReadWrite) {
Journal.commitJournal(journal);
} else if (analysis === Journal.JournalAnalysisInvalid) {
throw new Error("BUG: STM.TryCommit.tryCommit - please report an issue at https://github.com/Effect-TS/effect/issues");
}
switch (tExit._tag) {
case TExitOpCodes.OP_SUCCEED:
{
state.value = STMState.fromTExit(tExit);
return completeTodos(Exit.succeed(tExit.value), journal, scheduler, priority);
}
case TExitOpCodes.OP_FAIL:
{
state.value = STMState.fromTExit(tExit);
const cause = Cause.fail(tExit.error);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_DIE:
{
state.value = STMState.fromTExit(tExit);
const cause = Cause.die(tExit.defect);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_INTERRUPT:
{
state.value = STMState.fromTExit(tExit);
const cause = Cause.interrupt(fiberId);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_RETRY:
{
return TryCommit.suspend(journal);
}
}
};
/** @internal */
const tryCommitSync = (fiberId, stm, env, scheduler, priority) => {
const journal = new Map();
const tExit = new STMDriver(stm, journal, fiberId, env).run();
const analysis = Journal.analyzeJournal(journal);
if (analysis === Journal.JournalAnalysisReadWrite && TExit.isSuccess(tExit)) {
Journal.commitJournal(journal);
} else if (analysis === Journal.JournalAnalysisInvalid) {
throw new Error("BUG: STM.TryCommit.tryCommitSync - please report an issue at https://github.com/Effect-TS/effect/issues");
}
switch (tExit._tag) {
case TExitOpCodes.OP_SUCCEED:
{
return completeTodos(Exit.succeed(tExit.value), journal, scheduler, priority);
}
case TExitOpCodes.OP_FAIL:
{
const cause = Cause.fail(tExit.error);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_DIE:
{
const cause = Cause.die(tExit.defect);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_INTERRUPT:
{
const cause = Cause.interrupt(fiberId);
return completeTodos(Exit.failCause(cause), journal, scheduler, priority);
}
case TExitOpCodes.OP_RETRY:
{
return TryCommit.suspend(journal);
}
}
};
/** @internal */
const tryCommitAsync = (fiberId, self, txnId, state, context, scheduler, priority, k) => {
if (STMState.isRunning(state.value)) {
const result = tryCommit(fiberId, self, state, context, scheduler, priority);
switch (result._tag) {
case TryCommitOpCodes.OP_DONE:
{
completeTryCommit(result.exit, k);
break;
}
case TryCommitOpCodes.OP_SUSPEND:
{
Journal.addTodo(txnId, result.journal, () => tryCommitAsync(fiberId, self, txnId, state, context, scheduler, priority, k));
break;
}
}
}
};
/** @internal */
const completeTodos = (exit, journal, scheduler, priority) => {
const todos = Journal.collectTodos(journal);
if (todos.size > 0) {
scheduler.scheduleTask(() => Journal.execTodos(todos), priority);
}
return TryCommit.done(exit);
};
/** @internal */
const completeTryCommit = (exit, k) => {
k(exit);
};
/** @internal */
export const context = () => effect((_, __, env) => env);
/** @internal */
export const contextWith = f => map(context(), f);
/** @internal */
export const contextWithSTM = f => flatMap(context(), f);
/** @internal */
export class STMDriver {
self;
journal;
fiberId;
contStack = [];
env;
constructor(self, journal, fiberId, r0) {
this.self = self;
this.journal = journal;
this.fiberId = fiberId;
this.env = r0;
}
getEnv() {
return this.env;
}
pushStack(cont) {
this.contStack.push(cont);
}
popStack() {
return this.contStack.pop();
}
nextSuccess() {
let current = this.popStack();
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_SUCCESS) {
current = this.popStack();
}
return current;
}
nextFailure() {
let current = this.popStack();
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_FAILURE) {
current = this.popStack();
}
return current;
}
nextRetry() {
let current = this.popStack();
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_RETRY) {
current = this.popStack();
}
return current;
}
run() {
let curr = this.self;
let exit = undefined;
while (exit === undefined && curr !== undefined) {
try {
const current = curr;
if (current) {
switch (current._op) {
case "Tag":
{
curr = effect((_, __, env) => Context.unsafeGet(env, current));
break;
}
case "Left":
{
curr = fail(current.left);
break;
}
case "None":
{
curr = fail(new Cause.NoSuchElementException());
break;
}
case "Right":
{
curr = succeed(current.right);
break;
}
case "Some":
{
curr = succeed(current.value);
break;
}
case "Commit":
{
switch (current.effect_instruction_i0) {
case OpCodes.OP_DIE:
{
exit = TExit.die(internalCall(() => current.effect_instruction_i1()));
break;
}
case OpCodes.OP_FAIL:
{
const cont = this.nextFailure();
if (cont === undefined) {
exit = TExit.fail(internalCall(() => current.effect_instruction_i1()));
} else {
curr = internalCall(() => cont.effect_instruction_i2(internalCall(() => current.effect_instruction_i1())));
}
break;
}
case OpCodes.OP_RETRY:
{
const cont = this.nextRetry();
if (cont === undefined) {
exit = TExit.retry;
} else {
curr = internalCall(() => cont.effect_instruction_i2());
}
break;
}
case OpCodes.OP_INTERRUPT:
{
exit = TExit.interrupt(this.fiberId);
break;
}
case OpCodes.OP_WITH_STM_RUNTIME:
{
curr = internalCall(() => current.effect_instruction_i1(this));
break;
}
case OpCodes.OP_ON_SUCCESS:
case OpCodes.OP_ON_FAILURE:
case OpCodes.OP_ON_RETRY:
{
this.pushStack(current);
curr = current.effect_instruction_i1;
break;
}
case OpCodes.OP_PROVIDE:
{
const env = this.env;
this.env = internalCall(() => current.effect_instruction_i2(env));
curr = pipe(current.effect_instruction_i1, ensuring(sync(() => this.env = env)));
break;
}
case OpCodes.OP_SUCCEED:
{
const value = current.effect_instruction_i1;
const cont = this.nextSuccess();
if (cont === undefined) {
exit = TExit.succeed(value);
} else {
curr = internalCall(() => cont.effect_instruction_i2(value));
}
break;
}
case OpCodes.OP_SYNC:
{
const value = internalCall(() => current.effect_instruction_i1());
const cont = this.nextSuccess();
if (cont === undefined) {
exit = TExit.succeed(value);
} else {
curr = internalCall(() => cont.effect_instruction_i2(value));
}
break;
}
}
break;
}
}
}
} catch (e) {
curr = die(e);
}
}
return exit;
}
}
/** @internal */
export const catchAll = /*#__PURE__*/dual(2, (self, f) => {
const stm = new STMPrimitive(OpCodes.OP_ON_FAILURE);
stm.effect_instruction_i1 = self;
stm.effect_instruction_i2 = f;
return stm;
});
/** @internal */
export const mapInputContext = /*#__PURE__*/dual(2, (self, f) => {
const stm = new STMPrimitive(OpCodes.OP_PROVIDE);
stm.effect_instruction_i1 = self;
stm.effect_instruction_i2 = f;
return stm;
});
/** @internal */
export const die = defect => dieSync(() => defect);
/** @internal */
export const dieMessage = message => dieSync(() => new Cause.RuntimeException(message));
/** @internal */
export const dieSync = evaluate => {
const stm = new STMPrimitive(OpCodes.OP_DIE);
stm.effect_instruction_i1 = evaluate;
return stm;
};
/** @internal */
export const effect = f => withSTMRuntime(_ => succeed(f(_.journal, _.fiberId, _.getEnv())));
/** @internal */
export const ensuring = /*#__PURE__*/dual(2, (self, finalizer) => matchSTM(self, {
onFailure: e => zipRight(finalizer, fail(e)),
onSuccess: a => zipRight(finalizer, succeed(a))
}));
/** @internal */
export const fail = error => failSync(() => error);
/** @internal */
export const failSync = evaluate => {
const stm = new STMPrimitive(OpCodes.OP_FAIL);
stm.effect_instruction_i1 = evaluate;
return stm;
};
/** @internal */
export const flatMap = /*#__PURE__*/dual(2, (self, f) => {
const stm = new STMPrimitive(OpCodes.OP_ON_SUCCESS);
stm.effect_instruction_i1 = self;
stm.effect_instruction_i2 = f;
return stm;
});
/** @internal */
export const matchSTM = /*#__PURE__*/dual(2, (self, {
onFailure,
onSuccess
}) => pipe(self, map(Either.right), catchAll(e => pipe(onFailure(e), map(Either.left))), flatMap(either => {
switch (either._tag) {
case "Left":
{
return succeed(either.left);
}
case "Right":
{
return onSuccess(either.right);
}
}
})));
/** @internal */
export const withSTMRuntime = f => {
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME);
stm.effect_instruction_i1 = f;
return stm;
};
/** @internal */
export const interrupt = /*#__PURE__*/withSTMRuntime(_ => {
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT);
stm.effect_instruction_i1 = _.fiberId;
return stm;
});
/** @internal */
export const interruptAs = fiberId => {
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT);
stm.effect_instruction_i1 = fiberId;
return stm;
};
/** @internal */
export const map = /*#__PURE__*/dual(2, (self, f) => pipe(self, flatMap(a => sync(() => f(a)))));
/** @internal */
export const orTry = /*#__PURE__*/dual(2, (self, that) => {
const stm = new STMPrimitive(OpCodes.OP_ON_RETRY);
stm.effect_instruction_i1 = self;
stm.effect_instruction_i2 = that;
return stm;
});
/** @internal */
export const retry = /*#__PURE__*/new STMPrimitive(OpCodes.OP_RETRY);
/** @internal */
export const succeed = value => {
const stm = new STMPrimitive(OpCodes.OP_SUCCEED);
stm.effect_instruction_i1 = value;
return stm;
};
/** @internal */
export const sync = evaluate => {
const stm = new STMPrimitive(OpCodes.OP_SYNC);
stm.effect_instruction_i1 = evaluate;
return stm;
};
/** @internal */
export const zip = /*#__PURE__*/dual(2, (self, that) => pipe(self, zipWith(that, (a, a1) => [a, a1])));
/** @internal */
export const zipLeft = /*#__PURE__*/dual(2, (self, that) => pipe(self, flatMap(a => pipe(that, map(() => a)))));
/** @internal */
export const zipRight = /*#__PURE__*/dual(2, (self, that) => pipe(self, flatMap(() => that)));
/** @internal */
export const zipWith = /*#__PURE__*/dual(3, (self, that, f) => pipe(self, flatMap(a => pipe(that, map(b => f(a, b))))));
//# sourceMappingURL=core.js.map

File diff suppressed because one or more lines are too long

42
node_modules/effect/dist/esm/internal/stm/entry.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
import * as Versioned from "./versioned.js";
/** @internal */
export const make = (ref, isNew) => ({
ref,
isNew,
isChanged: false,
expected: ref.versioned,
newValue: ref.versioned.value
});
export const unsafeGet = self => {
return self.newValue;
};
/** @internal */
export const unsafeSet = (self, value) => {
self.isChanged = true;
self.newValue = value;
};
/** @internal */
export const commit = self => {
self.ref.versioned = new Versioned.Versioned(self.newValue);
};
/** @internal */
export const copy = self => ({
ref: self.ref,
isNew: self.isNew,
isChanged: self.isChanged,
expected: self.expected,
newValue: self.newValue
});
/** @internal */
export const isValid = self => {
return self.ref.versioned === self.expected;
};
/** @internal */
export const isInvalid = self => {
return self.ref.versioned !== self.expected;
};
/** @internal */
export const isChanged = self => {
return self.isChanged;
};
//# sourceMappingURL=entry.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"entry.js","names":["Versioned","make","ref","isNew","isChanged","expected","versioned","newValue","value","unsafeGet","self","unsafeSet","commit","copy","isValid","isInvalid"],"sources":["../../../../src/internal/stm/entry.ts"],"sourcesContent":[null],"mappings":"AACA,OAAO,KAAKA,SAAS,MAAM,gBAAgB;AAW3C;AACA,OAAO,MAAMC,IAAI,GAAGA,CAAIC,GAAiB,EAAEC,KAAc,MAAa;EACpED,GAAG;EACHC,KAAK;EACLC,SAAS,EAAE,KAAK;EAChBC,QAAQ,EAAEH,GAAG,CAACI,SAAS;EACvBC,QAAQ,EAAEL,GAAG,CAACI,SAAS,CAACE;CACzB,CAAC;AAEF,OAAO,MAAMC,SAAS,GAAIC,IAAW,IAAa;EAChD,OAAOA,IAAI,CAACH,QAAQ;AACtB,CAAC;AAED;AACA,OAAO,MAAMI,SAAS,GAAGA,CAACD,IAAW,EAAEF,KAAc,KAAU;EAC7DE,IAAI,CAACN,SAAS,GAAG,IAAI;EACrBM,IAAI,CAACH,QAAQ,GAAGC,KAAK;AACvB,CAAC;AAED;AACA,OAAO,MAAMI,MAAM,GAAIF,IAAW,IAAU;EAC1CA,IAAI,CAACR,GAAG,CAACI,SAAS,GAAG,IAAIN,SAAS,CAACA,SAAS,CAACU,IAAI,CAACH,QAAQ,CAAC;AAC7D,CAAC;AAED;AACA,OAAO,MAAMM,IAAI,GAAIH,IAAW,KAAa;EAC3CR,GAAG,EAAEQ,IAAI,CAACR,GAAG;EACbC,KAAK,EAAEO,IAAI,CAACP,KAAK;EACjBC,SAAS,EAAEM,IAAI,CAACN,SAAS;EACzBC,QAAQ,EAAEK,IAAI,CAACL,QAAQ;EACvBE,QAAQ,EAAEG,IAAI,CAACH;CAChB,CAAC;AAEF;AACA,OAAO,MAAMO,OAAO,GAAIJ,IAAW,IAAa;EAC9C,OAAOA,IAAI,CAACR,GAAG,CAACI,SAAS,KAAKI,IAAI,CAACL,QAAQ;AAC7C,CAAC;AAED;AACA,OAAO,MAAMU,SAAS,GAAIL,IAAW,IAAa;EAChD,OAAOA,IAAI,CAACR,GAAG,CAACI,SAAS,KAAKI,IAAI,CAACL,QAAQ;AAC7C,CAAC;AAED;AACA,OAAO,MAAMD,SAAS,GAAIM,IAAW,IAAa;EAChD,OAAOA,IAAI,CAACN,SAAS;AACvB,CAAC","ignoreList":[]}

89
node_modules/effect/dist/esm/internal/stm/journal.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
import * as Entry from "./entry.js";
/** @internal */
export const JournalAnalysisInvalid = "Invalid";
/** @internal */
export const JournalAnalysisReadWrite = "ReadWrite";
/** @internal */
export const JournalAnalysisReadOnly = "ReadOnly";
/** @internal */
export const commitJournal = journal => {
for (const entry of journal) {
Entry.commit(entry[1]);
}
};
/**
* Analyzes the journal, determining whether it is valid and whether it is
* read only in a single pass. Note that information on whether the
* journal is read only will only be accurate if the journal is valid, due
* to short-circuiting that occurs on an invalid journal.
*
* @internal
*/
export const analyzeJournal = journal => {
let val = JournalAnalysisReadOnly;
for (const [, entry] of journal) {
val = Entry.isInvalid(entry) ? JournalAnalysisInvalid : Entry.isChanged(entry) ? JournalAnalysisReadWrite : val;
if (val === JournalAnalysisInvalid) {
return val;
}
}
return val;
};
/** @internal */
export const prepareResetJournal = journal => {
const saved = new Map();
for (const entry of journal) {
saved.set(entry[0], Entry.copy(entry[1]));
}
return () => {
journal.clear();
for (const entry of saved) {
journal.set(entry[0], entry[1]);
}
};
};
/** @internal */
export const collectTodos = journal => {
const allTodos = new Map();
for (const [, entry] of journal) {
for (const todo of entry.ref.todos) {
allTodos.set(todo[0], todo[1]);
}
entry.ref.todos = new Map();
}
return allTodos;
};
/** @internal */
export const execTodos = todos => {
const todosSorted = Array.from(todos.entries()).sort((x, y) => x[0] - y[0]);
for (const [_, todo] of todosSorted) {
todo();
}
};
/** @internal */
export const addTodo = (txnId, journal, todoEffect) => {
let added = false;
for (const [, entry] of journal) {
if (!entry.ref.todos.has(txnId)) {
entry.ref.todos.set(txnId, todoEffect);
added = true;
}
}
return added;
};
/** @internal */
export const isValid = journal => {
let valid = true;
for (const [, entry] of journal) {
valid = Entry.isValid(entry);
if (!valid) {
return valid;
}
}
return valid;
};
/** @internal */
export const isInvalid = journal => {
return !isValid(journal);
};
//# sourceMappingURL=journal.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"journal.js","names":["Entry","JournalAnalysisInvalid","JournalAnalysisReadWrite","JournalAnalysisReadOnly","commitJournal","journal","entry","commit","analyzeJournal","val","isInvalid","isChanged","prepareResetJournal","saved","Map","set","copy","clear","collectTodos","allTodos","todo","ref","todos","execTodos","todosSorted","Array","from","entries","sort","x","y","_","addTodo","txnId","todoEffect","added","has","isValid","valid"],"sources":["../../../../src/internal/stm/journal.ts"],"sourcesContent":[null],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,YAAY;AAYnC;AACA,OAAO,MAAMC,sBAAsB,GAAG,SAAkB;AAKxD;AACA,OAAO,MAAMC,wBAAwB,GAAG,WAAoB;AAK5D;AACA,OAAO,MAAMC,uBAAuB,GAAG,UAAmB;AAK1D;AACA,OAAO,MAAMC,aAAa,GAAIC,OAAgB,IAAI;EAChD,KAAK,MAAMC,KAAK,IAAID,OAAO,EAAE;IAC3BL,KAAK,CAACO,MAAM,CAACD,KAAK,CAAC,CAAC,CAAC,CAAC;EACxB;AACF,CAAC;AAED;;;;;;;;AAQA,OAAO,MAAME,cAAc,GAAIH,OAAgB,IAAqB;EAClE,IAAII,GAAG,GAAoBN,uBAAuB;EAClD,KAAK,MAAM,GAAGG,KAAK,CAAC,IAAID,OAAO,EAAE;IAC/BI,GAAG,GAAGT,KAAK,CAACU,SAAS,CAACJ,KAAK,CAAC,GAAGL,sBAAsB,GAAGD,KAAK,CAACW,SAAS,CAACL,KAAK,CAAC,GAAGJ,wBAAwB,GAAGO,GAAG;IAC/G,IAAIA,GAAG,KAAKR,sBAAsB,EAAE;MAClC,OAAOQ,GAAG;IACZ;EACF;EACA,OAAOA,GAAG;AACZ,CAAC;AAED;AACA,OAAO,MAAMG,mBAAmB,GAAIP,OAAgB,IAAgB;EAClE,MAAMQ,KAAK,GAA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B5B,OAAgB,EAChB6B,UAAgB,KACL;EACX,IAAIC,KAAK,GAAG,KAAK;EACjB,KAAK,MAAM,GAAG7B,KAAK,CAAC,IAAID,OAAO,EAAE;IAC/B,IAAI,CAACC,KAAK,CAACe,GAAG,CAACC,KAAK,CAACc,GAAG,CAACH,KAAK,CAAC,EAAE;MAC/B3B,KAAK,CAACe,GAAG,CAACC,KAAK,CAACP,GAAG,CAACkB,KAAK,EAAEC,UAAU,CAAC;MACtCC,KAAK,GAAG,IAAI;IACd;EACF;EACA,OAAOA,KAAK;AACd,CAAC;AAED;AACA,OAAO,MAAME,OAAO,GAAIhC,OAAgB,IAAa;EACnD,IAAIiC,KAAK,GAAG,IAAI;EAChB,KAAK,MAAM,GAAGhC,KAAK,CAAC,IAAID,OAAO,EAAE;IAC/BiC,KAAK,GAAGtC,KAAK,CAACqC,OAAO,CAAC/B,KAAK,CAAC;IAC5B,IAAI,CAACgC,KAAK,EAAE;MACV,OAAOA,KAAK;IACd;EACF;EACA,OAAOA,KAAK;AACd,CAAC;AAED;AACA,OAAO,MAAM5B,SAAS,GAAIL,OAAgB,IAAa;EACrD,OAAO,CAACgC,OAAO,CAAChC,OAAO,CAAC;AAC1B,CAAC","ignoreList":[]}

View File

@@ -0,0 +1,25 @@
/** @internal */
export const OP_WITH_STM_RUNTIME = "WithSTMRuntime";
/** @internal */
export const OP_ON_FAILURE = "OnFailure";
/** @internal */
export const OP_ON_RETRY = "OnRetry";
/** @internal */
export const OP_ON_SUCCESS = "OnSuccess";
/** @internal */
export const OP_PROVIDE = "Provide";
/** @internal */
export const OP_SYNC = "Sync";
/** @internal */
export const OP_SUCCEED = "Succeed";
/** @internal */
export const OP_RETRY = "Retry";
/** @internal */
export const OP_FAIL = "Fail";
/** @internal */
export const OP_DIE = "Die";
/** @internal */
export const OP_INTERRUPT = "Interrupt";
/** @internal */
export const OP_TRACED = "Traced";
//# sourceMappingURL=stm.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stm.js","names":["OP_WITH_STM_RUNTIME","OP_ON_FAILURE","OP_ON_RETRY","OP_ON_SUCCESS","OP_PROVIDE","OP_SYNC","OP_SUCCEED","OP_RETRY","OP_FAIL","OP_DIE","OP_INTERRUPT","OP_TRACED"],"sources":["../../../../../src/internal/stm/opCodes/stm.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAO,MAAMA,mBAAmB,GAAG,gBAAyB;AAK5D;AACA,OAAO,MAAMC,aAAa,GAAG,WAAoB;AAKjD;AACA,OAAO,MAAMC,WAAW,GAAG,SAAkB;AAK7C;AACA,OAAO,MAAMC,aAAa,GAAG,WAAoB;AAKjD;AACA,OAAO,MAAMC,UAAU,GAAG,SAAkB;AAK5C;AACA,OAAO,MAAMC,OAAO,GAAG,MAAe;AAKtC;AACA,OAAO,MAAMC,UAAU,GAAG,SAAkB;AAK5C;AACA,OAAO,MAAMC,QAAQ,GAAG,OAAgB;AAKxC;AACA,OAAO,MAAMC,OAAO,GAAG,MAAe;AAKtC;AACA,OAAO,MAAMC,MAAM,GAAG,KAAc;AAKpC;AACA,OAAO,MAAMC,YAAY,GAAG,WAAoB;AAKhD;AACA,OAAO,MAAMC,SAAS,GAAG,QAAiB","ignoreList":[]}

View File

@@ -0,0 +1,7 @@
/** @internal */
export const OP_DONE = "Done";
/** @internal */
export const OP_INTERRUPTED = "Interrupted";
/** @internal */
export const OP_RUNNING = "Running";
//# sourceMappingURL=stmState.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stmState.js","names":["OP_DONE","OP_INTERRUPTED","OP_RUNNING"],"sources":["../../../../../src/internal/stm/opCodes/stmState.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,MAAe;AAKtC;AACA,OAAO,MAAMC,cAAc,GAAG,aAAsB;AAKpD;AACA,OAAO,MAAMC,UAAU,GAAG,SAAkB","ignoreList":[]}

View File

@@ -0,0 +1,7 @@
/** @internal */
export const OP_BACKPRESSURE_STRATEGY = "BackPressure";
/** @internal */
export const OP_DROPPING_STRATEGY = "Dropping";
/** @internal */
export const OP_SLIDING_STRATEGY = "Sliding";
//# sourceMappingURL=strategy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"strategy.js","names":["OP_BACKPRESSURE_STRATEGY","OP_DROPPING_STRATEGY","OP_SLIDING_STRATEGY"],"sources":["../../../../../src/internal/stm/opCodes/strategy.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAO,MAAMA,wBAAwB,GAAG,cAAuB;AAK/D;AACA,OAAO,MAAMC,oBAAoB,GAAG,UAAmB;AAKvD;AACA,OAAO,MAAMC,mBAAmB,GAAG,SAAkB","ignoreList":[]}

View File

@@ -0,0 +1,11 @@
/** @internal */
export const OP_FAIL = "Fail";
/** @internal */
export const OP_DIE = "Die";
/** @internal */
export const OP_INTERRUPT = "Interrupt";
/** @internal */
export const OP_SUCCEED = "Succeed";
/** @internal */
export const OP_RETRY = "Retry";
//# sourceMappingURL=tExit.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tExit.js","names":["OP_FAIL","OP_DIE","OP_INTERRUPT","OP_SUCCEED","OP_RETRY"],"sources":["../../../../../src/internal/stm/opCodes/tExit.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,MAAe;AAKtC;AACA,OAAO,MAAMC,MAAM,GAAG,KAAc;AAKpC;AACA,OAAO,MAAMC,YAAY,GAAG,WAAoB;AAKhD;AACA,OAAO,MAAMC,UAAU,GAAG,SAAkB;AAK5C;AACA,OAAO,MAAMC,QAAQ,GAAG,OAAgB","ignoreList":[]}

View File

@@ -0,0 +1,5 @@
/** @internal */
export const OP_DONE = "Done";
/** @internal */
export const OP_SUSPEND = "Suspend";
//# sourceMappingURL=tryCommit.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tryCommit.js","names":["OP_DONE","OP_SUSPEND"],"sources":["../../../../../src/internal/stm/opCodes/tryCommit.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,MAAe;AAKtC;AACA,OAAO,MAAMC,UAAU,GAAG,SAAkB","ignoreList":[]}

478
node_modules/effect/dist/esm/internal/stm/stm.js generated vendored Normal file
View File

@@ -0,0 +1,478 @@
import * as RA from "../../Array.js";
import * as Cause from "../../Cause.js";
import * as Chunk from "../../Chunk.js";
import * as Context from "../../Context.js";
import * as Effect from "../../Effect.js";
import * as Either from "../../Either.js";
import * as Exit from "../../Exit.js";
import { constFalse, constTrue, constVoid, dual, identity, pipe } from "../../Function.js";
import * as Option from "../../Option.js";
import * as predicate from "../../Predicate.js";
import { yieldWrapGet } from "../../Utils.js";
import * as effectCore from "../core.js";
import * as core from "./core.js";
import * as Journal from "./journal.js";
import * as STMState from "./stmState.js";
/** @internal */
export const acquireUseRelease = /*#__PURE__*/dual(3, (acquire, use, release) => Effect.uninterruptibleMask(restore => {
let state = STMState.running;
return pipe(restore(core.unsafeAtomically(acquire, exit => {
state = STMState.done(exit);
}, () => {
state = STMState.interrupted;
})), Effect.matchCauseEffect({
onFailure: cause => {
if (STMState.isDone(state) && Exit.isSuccess(state.exit)) {
return pipe(release(state.exit.value), Effect.matchCauseEffect({
onFailure: cause2 => Effect.failCause(Cause.parallel(cause, cause2)),
onSuccess: () => Effect.failCause(cause)
}));
}
return Effect.failCause(cause);
},
onSuccess: a => pipe(restore(use(a)), Effect.matchCauseEffect({
onFailure: cause => pipe(release(a), Effect.matchCauseEffect({
onFailure: cause2 => Effect.failCause(Cause.parallel(cause, cause2)),
onSuccess: () => Effect.failCause(cause)
})),
onSuccess: a2 => pipe(release(a), Effect.as(a2))
}))
}));
}));
/** @internal */
export const as = /*#__PURE__*/dual(2, (self, value) => pipe(self, core.map(() => value)));
/** @internal */
export const asSome = self => pipe(self, core.map(Option.some));
/** @internal */
export const asSomeError = self => pipe(self, mapError(Option.some));
/** @internal */
export const asVoid = self => pipe(self, core.map(constVoid));
/** @internal */
export const attempt = evaluate => suspend(() => {
try {
return core.succeed(evaluate());
} catch (defect) {
return core.fail(defect);
}
});
export const bind = /*#__PURE__*/dual(3, (self, tag, f) => core.flatMap(self, k => core.map(f(k), a => ({
...k,
[tag]: a
}))));
/* @internal */
export const bindTo = /*#__PURE__*/dual(2, (self, tag) => core.map(self, a => ({
[tag]: a
})));
/* @internal */
export const let_ = /*#__PURE__*/dual(3, (self, tag, f) => core.map(self, k => ({
...k,
[tag]: f(k)
})));
/** @internal */
export const catchSome = /*#__PURE__*/dual(2, (self, pf) => core.catchAll(self, e => Option.getOrElse(pf(e), () => core.fail(e))));
/** @internal */
export const catchTag = /*#__PURE__*/dual(3, (self, k, f) => core.catchAll(self, e => {
if ("_tag" in e && e["_tag"] === k) {
return f(e);
}
return core.fail(e);
}));
/** @internal */
export const catchTags = /*#__PURE__*/dual(2, (self, cases) => core.catchAll(self, e => {
const keys = Object.keys(cases);
if ("_tag" in e && keys.includes(e["_tag"])) {
return cases[e["_tag"]](e);
}
return core.fail(e);
}));
/** @internal */
export const check = predicate => suspend(() => predicate() ? void_ : core.retry);
/** @internal */
export const collect = /*#__PURE__*/dual(2, (self, pf) => collectSTM(self, a => Option.map(pf(a), core.succeed)));
/** @internal */
export const collectSTM = /*#__PURE__*/dual(2, (self, pf) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => {
const option = pf(a);
return Option.isSome(option) ? option.value : core.retry;
}
}));
/** @internal */
export const commitEither = self => Effect.flatten(core.commit(either(self)));
/** @internal */
export const cond = (predicate, error, result) => {
return suspend(() => predicate() ? core.sync(result) : core.failSync(error));
};
/** @internal */
export const either = self => match(self, {
onFailure: Either.left,
onSuccess: Either.right
});
/** @internal */
export const eventually = self => core.matchSTM(self, {
onFailure: () => eventually(self),
onSuccess: core.succeed
});
/** @internal */
export const every = /*#__PURE__*/dual(2, (iterable, predicate) => pipe(core.flatMap(core.sync(() => iterable[Symbol.iterator]()), iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return core.succeed(true);
}
return pipe(predicate(next.value), core.flatMap(bool => bool ? loop : core.succeed(bool)));
});
return loop;
})));
/** @internal */
export const exists = /*#__PURE__*/dual(2, (iterable, predicate) => core.flatMap(core.sync(() => iterable[Symbol.iterator]()), iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return core.succeed(false);
}
return core.flatMap(predicate(next.value), bool => bool ? core.succeed(bool) : loop);
});
return loop;
}));
/** @internal */
export const fiberId = /*#__PURE__*/core.effect((_, fiberId) => fiberId);
/** @internal */
export const filter = /*#__PURE__*/dual(2, (iterable, predicate) => Array.from(iterable).reduce((acc, curr) => pipe(acc, core.zipWith(predicate(curr), (as, p) => {
if (p) {
as.push(curr);
return as;
}
return as;
})), core.succeed([])));
/** @internal */
export const filterNot = /*#__PURE__*/dual(2, (iterable, predicate) => filter(iterable, a => negate(predicate(a))));
/** @internal */
export const filterOrDie = /*#__PURE__*/dual(3, (self, predicate, defect) => filterOrElse(self, predicate, () => core.dieSync(defect)));
/** @internal */
export const filterOrDieMessage = /*#__PURE__*/dual(3, (self, predicate, message) => filterOrElse(self, predicate, () => core.dieMessage(message)));
/** @internal */
export const filterOrElse = /*#__PURE__*/dual(3, (self, predicate, orElse) => core.flatMap(self, a => predicate(a) ? core.succeed(a) : orElse(a)));
/** @internal */
export const filterOrFail = /*#__PURE__*/dual(3, (self, predicate, orFailWith) => filterOrElse(self, predicate, a => core.failSync(() => orFailWith(a))));
/** @internal */
export const flatten = self => core.flatMap(self, identity);
/** @internal */
export const flip = self => core.matchSTM(self, {
onFailure: core.succeed,
onSuccess: core.fail
});
/** @internal */
export const flipWith = /*#__PURE__*/dual(2, (self, f) => flip(f(flip(self))));
/** @internal */
export const match = /*#__PURE__*/dual(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => core.succeed(onFailure(e)),
onSuccess: a => core.succeed(onSuccess(a))
}));
/** @internal */
export const forEach = /*#__PURE__*/dual(args => predicate.isIterable(args[0]), (iterable, f, options) => {
if (options?.discard) {
return pipe(core.sync(() => iterable[Symbol.iterator]()), core.flatMap(iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return void_;
}
return pipe(f(next.value), core.flatMap(() => loop));
});
return loop;
}));
}
return suspend(() => RA.fromIterable(iterable).reduce((acc, curr) => core.zipWith(acc, f(curr), (array, elem) => {
array.push(elem);
return array;
}), core.succeed([])));
});
/** @internal */
export const fromEither = either => {
switch (either._tag) {
case "Left":
{
return core.fail(either.left);
}
case "Right":
{
return core.succeed(either.right);
}
}
};
/** @internal */
export const fromOption = option => Option.match(option, {
onNone: () => core.fail(Option.none()),
onSome: core.succeed
});
/**
* Inspired by https://github.com/tusharmath/qio/pull/22 (revised)
* @internal
*/
export const gen = (...args) => suspend(() => {
const f = args.length === 1 ? args[0] : args[1].bind(args[0]);
const iterator = f(pipe);
const state = iterator.next();
const run = state => state.done ? core.succeed(state.value) : core.flatMap(yieldWrapGet(state.value), val => run(iterator.next(val)));
return run(state);
});
/** @internal */
export const head = self => pipe(self, core.matchSTM({
onFailure: e => core.fail(Option.some(e)),
onSuccess: a => {
const i = a[Symbol.iterator]();
const res = i.next();
if (res.done) {
return core.fail(Option.none());
} else {
return core.succeed(res.value);
}
}
}));
/** @internal */
export const if_ = /*#__PURE__*/dual(args => typeof args[0] === "boolean" || core.isSTM(args[0]), (self, {
onFalse,
onTrue
}) => {
if (typeof self === "boolean") {
return self ? onTrue : onFalse;
}
return core.flatMap(self, bool => bool ? onTrue : onFalse);
});
/** @internal */
export const ignore = self => match(self, {
onFailure: () => void_,
onSuccess: () => void_
});
/** @internal */
export const isFailure = self => match(self, {
onFailure: constTrue,
onSuccess: constFalse
});
/** @internal */
export const isSuccess = self => match(self, {
onFailure: constFalse,
onSuccess: constTrue
});
/** @internal */
export const iterate = (initial, options) => iterateLoop(initial, options.while, options.body);
const iterateLoop = (initial, cont, body) => {
if (cont(initial)) {
return pipe(body(initial), core.flatMap(z => iterateLoop(z, cont, body)));
}
return core.succeed(initial);
};
/** @internal */
export const loop = (initial, options) => options.discard ? loopDiscardLoop(initial, options.while, options.step, options.body) : core.map(loopLoop(initial, options.while, options.step, options.body), a => Array.from(a));
const loopLoop = (initial, cont, inc, body) => {
if (cont(initial)) {
return pipe(body(initial), core.flatMap(a => pipe(loopLoop(inc(initial), cont, inc, body), core.map(Chunk.append(a)))));
}
return core.succeed(Chunk.empty());
};
const loopDiscardLoop = (initial, cont, inc, body) => {
if (cont(initial)) {
return pipe(body(initial), core.flatMap(() => loopDiscardLoop(inc(initial), cont, inc, body)));
}
return void_;
};
/** @internal */
export const mapAttempt = /*#__PURE__*/dual(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.fail(e),
onSuccess: a => attempt(() => f(a))
}));
/** @internal */
export const mapBoth = /*#__PURE__*/dual(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => core.fail(onFailure(e)),
onSuccess: a => core.succeed(onSuccess(a))
}));
/** @internal */
export const mapError = /*#__PURE__*/dual(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.fail(f(e)),
onSuccess: core.succeed
}));
/** @internal */
export const merge = self => core.matchSTM(self, {
onFailure: e => core.succeed(e),
onSuccess: core.succeed
});
/** @internal */
export const mergeAll = /*#__PURE__*/dual(3, (iterable, zero, f) => suspend(() => Array.from(iterable).reduce((acc, curr) => pipe(acc, core.zipWith(curr, f)), core.succeed(zero))));
/** @internal */
export const negate = self => pipe(self, core.map(b => !b));
/** @internal */
export const none = self => core.matchSTM(self, {
onFailure: e => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => void_,
onSome: () => core.fail(Option.none())
})
});
/** @internal */
export const option = self => match(self, {
onFailure: () => Option.none(),
onSuccess: Option.some
});
/** @internal */
export const orDie = self => pipe(self, orDieWith(identity));
/** @internal */
export const orDieWith = /*#__PURE__*/dual(2, (self, f) => pipe(self, mapError(f), core.catchAll(core.die)));
/** @internal */
export const orElse = /*#__PURE__*/dual(2, (self, that) => core.flatMap(core.effect(journal => Journal.prepareResetJournal(journal)), reset => pipe(core.orTry(self, () => core.flatMap(core.sync(reset), that)), core.catchAll(() => core.flatMap(core.sync(reset), that)))));
/** @internal */
export const orElseEither = /*#__PURE__*/dual(2, (self, that) => orElse(core.map(self, Either.left), () => core.map(that(), Either.right)));
/** @internal */
export const orElseFail = /*#__PURE__*/dual(2, (self, error) => orElse(self, () => core.failSync(error)));
/** @internal */
export const orElseOptional = /*#__PURE__*/dual(2, (self, that) => core.catchAll(self, Option.match({
onNone: that,
onSome: e => core.fail(Option.some(e))
})));
/** @internal */
export const orElseSucceed = /*#__PURE__*/dual(2, (self, value) => orElse(self, () => core.sync(value)));
/** @internal */
export const provideContext = /*#__PURE__*/dual(2, (self, env) => core.mapInputContext(self, _ => env));
/** @internal */
export const provideSomeContext = /*#__PURE__*/dual(2, (self, context) => core.mapInputContext(self, parent => Context.merge(parent, context)));
/** @internal */
export const provideService = /*#__PURE__*/dual(3, (self, tag, resource) => provideServiceSTM(self, tag, core.succeed(resource)));
/** @internal */
export const provideServiceSTM = /*#__PURE__*/dual(3, (self, tag, stm) => core.contextWithSTM(env => core.flatMap(stm, service => provideContext(self, Context.add(env, tag, service)))));
/** @internal */
export const reduce = /*#__PURE__*/dual(3, (iterable, zero, f) => suspend(() => Array.from(iterable).reduce((acc, curr) => pipe(acc, core.flatMap(s => f(s, curr))), core.succeed(zero))));
/** @internal */
export const reduceAll = /*#__PURE__*/dual(3, (iterable, initial, f) => suspend(() => Array.from(iterable).reduce((acc, curr) => pipe(acc, core.zipWith(curr, f)), initial)));
/** @internal */
export const reduceRight = /*#__PURE__*/dual(3, (iterable, zero, f) => suspend(() => Array.from(iterable).reduceRight((acc, curr) => pipe(acc, core.flatMap(s => f(s, curr))), core.succeed(zero))));
/** @internal */
export const refineOrDie = /*#__PURE__*/dual(2, (self, pf) => refineOrDieWith(self, pf, identity));
/** @internal */
export const refineOrDieWith = /*#__PURE__*/dual(3, (self, pf, f) => core.catchAll(self, e => Option.match(pf(e), {
onNone: () => core.die(f(e)),
onSome: core.fail
})));
/** @internal */
export const reject = /*#__PURE__*/dual(2, (self, pf) => rejectSTM(self, a => Option.map(pf(a), core.fail)));
/** @internal */
export const rejectSTM = /*#__PURE__*/dual(2, (self, pf) => core.flatMap(self, a => Option.match(pf(a), {
onNone: () => core.succeed(a),
onSome: core.flatMap(core.fail)
})));
/** @internal */
export const repeatUntil = /*#__PURE__*/dual(2, (self, predicate) => repeatUntilLoop(self, predicate));
const repeatUntilLoop = (self, predicate) => core.flatMap(self, a => predicate(a) ? core.succeed(a) : repeatUntilLoop(self, predicate));
/** @internal */
export const repeatWhile = /*#__PURE__*/dual(2, (self, predicate) => repeatWhileLoop(self, predicate));
const repeatWhileLoop = (self, predicate) => pipe(core.flatMap(self, a => predicate(a) ? repeatWhileLoop(self, predicate) : core.succeed(a)));
/** @internal */
export const replicate = /*#__PURE__*/dual(2, (self, n) => Array.from({
length: n
}, () => self));
/** @internal */
export const replicateSTM = /*#__PURE__*/dual(2, (self, n) => all(replicate(self, n)));
/** @internal */
export const replicateSTMDiscard = /*#__PURE__*/dual(2, (self, n) => all(replicate(self, n), {
discard: true
}));
/** @internal */
export const retryUntil = /*#__PURE__*/dual(2, (self, predicate) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => predicate(a) ? core.succeed(a) : core.retry
}));
/** @internal */
export const retryWhile = /*#__PURE__*/dual(2, (self, predicate) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => !predicate(a) ? core.succeed(a) : core.retry
}));
/** @internal */
export const partition = /*#__PURE__*/dual(2, (elements, f) => pipe(forEach(elements, a => either(f(a))), core.map(as => effectCore.partitionMap(as, identity))));
/** @internal */
export const some = self => core.matchSTM(self, {
onFailure: e => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => core.fail(Option.none()),
onSome: core.succeed
})
});
/* @internal */
export const all = (input, options) => {
if (Symbol.iterator in input) {
return forEach(input, identity, options);
} else if (options?.discard) {
return forEach(Object.values(input), identity, options);
}
return core.map(forEach(Object.entries(input), ([_, e]) => core.map(e, a => [_, a])), values => {
const res = {};
for (const [k, v] of values) {
;
res[k] = v;
}
return res;
});
};
/** @internal */
export const succeedNone = /*#__PURE__*/core.succeed(/*#__PURE__*/Option.none());
/** @internal */
export const succeedSome = value => core.succeed(Option.some(value));
/** @internal */
export const summarized = /*#__PURE__*/dual(3, (self, summary, f) => core.flatMap(summary, start => core.flatMap(self, value => core.map(summary, end => [f(start, end), value]))));
/** @internal */
export const suspend = evaluate => flatten(core.sync(evaluate));
/** @internal */
export const tap = /*#__PURE__*/dual(2, (self, f) => core.flatMap(self, a => as(f(a), a)));
/** @internal */
export const tapBoth = /*#__PURE__*/dual(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => pipe(onFailure(e), core.zipRight(core.fail(e))),
onSuccess: a => pipe(onSuccess(a), as(a))
}));
/** @internal */
export const tapError = /*#__PURE__*/dual(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.zipRight(f(e), core.fail(e)),
onSuccess: core.succeed
}));
/** @internal */
export const try_ = arg => {
const evaluate = typeof arg === "function" ? arg : arg.try;
return suspend(() => {
try {
return core.succeed(evaluate());
} catch (error) {
return core.fail("catch" in arg ? arg.catch(error) : error);
}
});
};
/** @internal */
const void_ = /*#__PURE__*/core.succeed(void 0);
export { /** @internal */
void_ as void };
/** @internal */
export const unless = /*#__PURE__*/dual(2, (self, predicate) => suspend(() => predicate() ? succeedNone : asSome(self)));
/** @internal */
export const unlessSTM = /*#__PURE__*/dual(2, (self, predicate) => core.flatMap(predicate, bool => bool ? succeedNone : asSome(self)));
/** @internal */
export const unsome = self => core.matchSTM(self, {
onFailure: Option.match({
onNone: () => core.succeed(Option.none()),
onSome: core.fail
}),
onSuccess: a => core.succeed(Option.some(a))
});
/** @internal */
export const validateAll = /*#__PURE__*/dual(2, (elements, f) => core.flatMap(partition(elements, f), ([errors, values]) => RA.isNonEmptyArray(errors) ? core.fail(errors) : core.succeed(values)));
/** @internal */
export const validateFirst = /*#__PURE__*/dual(2, (elements, f) => flip(forEach(elements, a => flip(f(a)))));
/** @internal */
export const when = /*#__PURE__*/dual(2, (self, predicate) => suspend(() => predicate() ? asSome(self) : succeedNone));
/** @internal */
export const whenSTM = /*#__PURE__*/dual(2, (self, predicate) => core.flatMap(predicate, bool => bool ? asSome(self) : succeedNone));
//# sourceMappingURL=stm.js.map

1
node_modules/effect/dist/esm/internal/stm/stm.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

89
node_modules/effect/dist/esm/internal/stm/stmState.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
import * as Equal from "../../Equal.js";
import * as Exit from "../../Exit.js";
import { pipe } from "../../Function.js";
import * as Hash from "../../Hash.js";
import { hasProperty } from "../../Predicate.js";
import * as OpCodes from "./opCodes/stmState.js";
import * as TExitOpCodes from "./opCodes/tExit.js";
/** @internal */
const STMStateSymbolKey = "effect/STM/State";
/** @internal */
export const STMStateTypeId = /*#__PURE__*/Symbol.for(STMStateSymbolKey);
/** @internal */
export const isSTMState = u => hasProperty(u, STMStateTypeId);
/** @internal */
export const isRunning = self => {
return self._tag === OpCodes.OP_RUNNING;
};
/** @internal */
export const isDone = self => {
return self._tag === OpCodes.OP_DONE;
};
/** @internal */
export const isInterrupted = self => {
return self._tag === OpCodes.OP_INTERRUPTED;
};
/** @internal */
export const done = exit => {
return {
[STMStateTypeId]: STMStateTypeId,
_tag: OpCodes.OP_DONE,
exit,
[Hash.symbol]() {
return pipe(Hash.hash(STMStateSymbolKey), Hash.combine(Hash.hash(OpCodes.OP_DONE)), Hash.combine(Hash.hash(exit)), Hash.cached(this));
},
[Equal.symbol](that) {
return isSTMState(that) && that._tag === OpCodes.OP_DONE && Equal.equals(exit, that.exit);
}
};
};
const interruptedHash = /*#__PURE__*/pipe(/*#__PURE__*/Hash.hash(STMStateSymbolKey), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash(OpCodes.OP_INTERRUPTED)), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash("interrupted")));
/** @internal */
export const interrupted = {
[STMStateTypeId]: STMStateTypeId,
_tag: OpCodes.OP_INTERRUPTED,
[Hash.symbol]() {
return interruptedHash;
},
[Equal.symbol](that) {
return isSTMState(that) && that._tag === OpCodes.OP_INTERRUPTED;
}
};
const runningHash = /*#__PURE__*/pipe(/*#__PURE__*/Hash.hash(STMStateSymbolKey), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash(OpCodes.OP_RUNNING)), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash("running")));
/** @internal */
export const running = {
[STMStateTypeId]: STMStateTypeId,
_tag: OpCodes.OP_RUNNING,
[Hash.symbol]() {
return runningHash;
},
[Equal.symbol](that) {
return isSTMState(that) && that._tag === OpCodes.OP_RUNNING;
}
};
/** @internal */
export const fromTExit = tExit => {
switch (tExit._tag) {
case TExitOpCodes.OP_FAIL:
{
return done(Exit.fail(tExit.error));
}
case TExitOpCodes.OP_DIE:
{
return done(Exit.die(tExit.defect));
}
case TExitOpCodes.OP_INTERRUPT:
{
return done(Exit.interrupt(tExit.fiberId));
}
case TExitOpCodes.OP_SUCCEED:
{
return done(Exit.succeed(tExit.value));
}
case TExitOpCodes.OP_RETRY:
{
throw new Error("BUG: STM.STMState.fromTExit - please report an issue at https://github.com/Effect-TS/effect/issues");
}
}
};
//# sourceMappingURL=stmState.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stmState.js","names":["Equal","Exit","pipe","Hash","hasProperty","OpCodes","TExitOpCodes","STMStateSymbolKey","STMStateTypeId","Symbol","for","isSTMState","u","isRunning","self","_tag","OP_RUNNING","isDone","OP_DONE","isInterrupted","OP_INTERRUPTED","done","exit","symbol","hash","combine","cached","that","equals","interruptedHash","interrupted","runningHash","running","fromTExit","tExit","OP_FAIL","fail","error","OP_DIE","die","defect","OP_INTERRUPT","interrupt","fiberId","OP_SUCCEED","succeed","value","OP_RETRY","Error"],"sources":["../../../../src/internal/stm/stmState.ts"],"sourc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xB,cAAc,GAAGA,cAAc;EAChCO,IAAI,EAAEV,OAAO,CAACW,UAAU;EACxB,CAACb,IAAI,CAACoB,MAAM,IAAC;IACX,OAAOQ,WAAW;EACpB,CAAC;EACD,CAAC/B,KAAK,CAACuB,MAAM,EAAEI,IAAa;IAC1B,OAAOhB,UAAU,CAACgB,IAAI,CAAC,IAAIA,IAAI,CAACZ,IAAI,KAAKV,OAAO,CAACW,UAAU;EAC7D;CACD;AAED;AACA,OAAO,MAAMiB,SAAS,GAAUC,KAAwB,IAAoB;EAC1E,QAAQA,KAAK,CAACnB,IAAI;IAChB,KAAKT,YAAY,CAAC6B,OAAO;MAAE;QACzB,OAAOd,IAAI,CAACpB,IAAI,CAACmC,IAAI,CAACF,KAAK,CAACG,KAAK,CAAC,CAAC;MACrC;IACA,KAAK/B,YAAY,CAACgC,MAAM;MAAE;QACxB,OAAOjB,IAAI,CAACpB,IAAI,CAACsC,GAAG,CAACL,KAAK,CAACM,MAAM,CAAC,CAAC;MACrC;IACA,KAAKlC,YAAY,CAACmC,YAAY;MAAE;QAC9B,OAAOpB,IAAI,CAACpB,IAAI,CAACyC,SAAS,CAACR,KAAK,CAACS,OAAO,CAAC,CAAC;MAC5C;IACA,KAAKrC,YAAY,CAACsC,UAAU;MAAE;QAC5B,OAAOvB,IAAI,CAACpB,IAAI,CAAC4C,OAAO,CAACX,KAAK,CAACY,KAAK,CAAC,CAAC;MACxC;IACA,KAAKxC,YAAY,CAACyC,QAAQ;MAAE;QAC1B,MAAM,IAAIC,KAAK,CACb,oGAAoG,CACrG;MACH;EACF;AACF,CAAC","ignoreList":[]}

243
node_modules/effect/dist/esm/internal/stm/tArray.js generated vendored Normal file
View File

@@ -0,0 +1,243 @@
import * as Equal from "../../Equal.js";
import { dual, pipe } from "../../Function.js";
import * as Option from "../../Option.js";
import * as Order from "../../Order.js";
import * as core from "./core.js";
import * as stm from "./stm.js";
import * as tRef from "./tRef.js";
/** @internal */
const TArraySymbolKey = "effect/TArray";
/** @internal */
export const TArrayTypeId = /*#__PURE__*/Symbol.for(TArraySymbolKey);
const tArrayVariance = {
/* c8 ignore next */
_A: _ => _
};
/** @internal */
export class TArrayImpl {
chunk;
[TArrayTypeId] = tArrayVariance;
constructor(chunk) {
this.chunk = chunk;
}
}
/** @internal */
export const collectFirst = /*#__PURE__*/dual(2, (self, pf) => collectFirstSTM(self, a => pipe(pf(a), Option.map(core.succeed))));
/** @internal */
export const collectFirstSTM = /*#__PURE__*/dual(2, (self, pf) => core.withSTMRuntime(runtime => {
let index = 0;
let result = Option.none();
while (Option.isNone(result) && index < self.chunk.length) {
const element = pipe(self.chunk[index], tRef.unsafeGet(runtime.journal));
const option = pf(element);
if (Option.isSome(option)) {
result = option;
}
index = index + 1;
}
return pipe(result, Option.match({
onNone: () => stm.succeedNone,
onSome: core.map(Option.some)
}));
}));
/** @internal */
export const contains = /*#__PURE__*/dual(2, (self, value) => some(self, a => Equal.equals(a)(value)));
/** @internal */
export const count = /*#__PURE__*/dual(2, (self, predicate) => reduce(self, 0, (n, a) => predicate(a) ? n + 1 : n));
/** @internal */
export const countSTM = /*#__PURE__*/dual(2, (self, predicate) => reduceSTM(self, 0, (n, a) => core.map(predicate(a), bool => bool ? n + 1 : n)));
/** @internal */
export const empty = () => fromIterable([]);
/** @internal */
export const every = /*#__PURE__*/dual(2, (self, predicate) => stm.negate(some(self, a => !predicate(a))));
/** @internal */
export const everySTM = /*#__PURE__*/dual(2, (self, predicate) => core.map(countSTM(self, predicate), count => count === self.chunk.length));
/** @internal */
export const findFirst = /*#__PURE__*/dual(2, (self, predicate) => collectFirst(self, a => predicate(a) ? Option.some(a) : Option.none()));
/** @internal */
export const findFirstIndex = /*#__PURE__*/dual(2, (self, value) => findFirstIndexFrom(self, value, 0));
/** @internal */
export const findFirstIndexFrom = /*#__PURE__*/dual(3, (self, value, from) => findFirstIndexWhereFrom(self, a => Equal.equals(a)(value), from));
/** @internal */
export const findFirstIndexWhere = /*#__PURE__*/dual(2, (self, predicate) => findFirstIndexWhereFrom(self, predicate, 0));
/** @internal */
export const findFirstIndexWhereFrom = /*#__PURE__*/dual(3, (self, predicate, from) => {
if (from < 0) {
return stm.succeedNone;
}
return core.effect(journal => {
let index = from;
let found = false;
while (!found && index < self.chunk.length) {
const element = tRef.unsafeGet(self.chunk[index], journal);
found = predicate(element);
index = index + 1;
}
if (found) {
return Option.some(index - 1);
}
return Option.none();
});
});
/** @internal */
export const findFirstIndexWhereSTM = /*#__PURE__*/dual(2, (self, predicate) => findFirstIndexWhereFromSTM(self, predicate, 0));
/** @internal */
export const findFirstIndexWhereFromSTM = /*#__PURE__*/dual(3, (self, predicate, from) => {
const forIndex = index => index < self.chunk.length ? pipe(tRef.get(self.chunk[index]), core.flatMap(predicate), core.flatMap(bool => bool ? core.succeed(Option.some(index)) : forIndex(index + 1))) : stm.succeedNone;
return from < 0 ? stm.succeedNone : forIndex(from);
});
/** @internal */
export const findFirstSTM = /*#__PURE__*/dual(2, (self, predicate) => {
const init = [Option.none(), 0];
const cont = state => Option.isNone(state[0]) && state[1] < self.chunk.length - 1;
return core.map(stm.iterate(init, {
while: cont,
body: state => {
const index = state[1];
return pipe(tRef.get(self.chunk[index]), core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index + 1])));
}
}), state => state[0]);
});
/** @internal */
export const findLast = /*#__PURE__*/dual(2, (self, predicate) => core.effect(journal => {
let index = self.chunk.length - 1;
let result = Option.none();
while (Option.isNone(result) && index >= 0) {
const element = tRef.unsafeGet(self.chunk[index], journal);
if (predicate(element)) {
result = Option.some(element);
}
index = index - 1;
}
return result;
}));
/** @internal */
export const findLastIndex = /*#__PURE__*/dual(2, (self, value) => findLastIndexFrom(self, value, self.chunk.length - 1));
/** @internal */
export const findLastIndexFrom = /*#__PURE__*/dual(3, (self, value, end) => {
if (end >= self.chunk.length) {
return stm.succeedNone;
}
return core.effect(journal => {
let index = end;
let found = false;
while (!found && index >= 0) {
const element = tRef.unsafeGet(self.chunk[index], journal);
found = Equal.equals(element)(value);
index = index - 1;
}
if (found) {
return Option.some(index + 1);
}
return Option.none();
});
});
/** @internal */
export const findLastSTM = /*#__PURE__*/dual(2, (self, predicate) => {
const init = [Option.none(), self.chunk.length - 1];
const cont = state => Option.isNone(state[0]) && state[1] >= 0;
return core.map(stm.iterate(init, {
while: cont,
body: state => {
const index = state[1];
return pipe(tRef.get(self.chunk[index]), core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index - 1])));
}
}), state => state[0]);
});
/** @internal */
export const forEach = /*#__PURE__*/dual(2, (self, f) => reduceSTM(self, void 0, (_, a) => f(a)));
/** @internal */
export const fromIterable = iterable => core.map(stm.forEach(iterable, tRef.make), chunk => new TArrayImpl(chunk));
/** @internal */
export const get = /*#__PURE__*/dual(2, (self, index) => {
if (index < 0 || index >= self.chunk.length) {
return core.dieMessage("Index out of bounds");
}
return tRef.get(self.chunk[index]);
});
/** @internal */
export const headOption = self => self.chunk.length === 0 ? core.succeed(Option.none()) : core.map(tRef.get(self.chunk[0]), Option.some);
/** @internal */
export const lastOption = self => self.chunk.length === 0 ? stm.succeedNone : core.map(tRef.get(self.chunk[self.chunk.length - 1]), Option.some);
/** @internal */
export const make = (...elements) => fromIterable(elements);
/** @internal */
export const maxOption = /*#__PURE__*/dual(2, (self, order) => {
const greaterThan = Order.greaterThan(order);
return reduceOption(self, (acc, curr) => greaterThan(acc)(curr) ? curr : acc);
});
/** @internal */
export const minOption = /*#__PURE__*/dual(2, (self, order) => {
const lessThan = Order.lessThan(order);
return reduceOption(self, (acc, curr) => lessThan(acc)(curr) ? curr : acc);
});
/** @internal */
export const reduce = /*#__PURE__*/dual(3, (self, zero, f) => core.effect(journal => {
let index = 0;
let result = zero;
while (index < self.chunk.length) {
const element = tRef.unsafeGet(self.chunk[index], journal);
result = f(result, element);
index = index + 1;
}
return result;
}));
/** @internal */
export const reduceOption = /*#__PURE__*/dual(2, (self, f) => core.effect(journal => {
let index = 0;
let result = undefined;
while (index < self.chunk.length) {
const element = tRef.unsafeGet(self.chunk[index], journal);
result = result === undefined ? element : f(result, element);
index = index + 1;
}
return Option.fromNullable(result);
}));
/** @internal */
export const reduceOptionSTM = /*#__PURE__*/dual(2, (self, f) => reduceSTM(self, Option.none(), (acc, curr) => Option.isSome(acc) ? core.map(f(acc.value, curr), Option.some) : stm.succeedSome(curr)));
/** @internal */
export const reduceSTM = /*#__PURE__*/dual(3, (self, zero, f) => core.flatMap(toArray(self), stm.reduce(zero, f)));
/** @internal */
export const size = self => self.chunk.length;
/** @internal */
export const some = /*#__PURE__*/dual(2, (self, predicate) => core.map(findFirst(self, predicate), Option.isSome));
/** @internal */
export const someSTM = /*#__PURE__*/dual(2, (self, predicate) => core.map(countSTM(self, predicate), n => n > 0));
/** @internal */
export const toArray = self => stm.forEach(self.chunk, tRef.get);
/** @internal */
export const transform = /*#__PURE__*/dual(2, (self, f) => core.effect(journal => {
let index = 0;
while (index < self.chunk.length) {
const ref = self.chunk[index];
tRef.unsafeSet(ref, f(tRef.unsafeGet(ref, journal)), journal);
index = index + 1;
}
return void 0;
}));
/** @internal */
export const transformSTM = /*#__PURE__*/dual(2, (self, f) => core.flatMap(stm.forEach(self.chunk, ref => core.flatMap(tRef.get(ref), f)), chunk => core.effect(journal => {
const iterator = chunk[Symbol.iterator]();
let index = 0;
let next;
while ((next = iterator.next()) && !next.done) {
tRef.unsafeSet(self.chunk[index], next.value, journal);
index = index + 1;
}
return void 0;
})));
/** @internal */
export const update = /*#__PURE__*/dual(3, (self, index, f) => {
if (index < 0 || index >= self.chunk.length) {
return core.dieMessage("Index out of bounds");
}
return tRef.update(self.chunk[index], f);
});
/** @internal */
export const updateSTM = /*#__PURE__*/dual(3, (self, index, f) => {
if (index < 0 || index >= self.chunk.length) {
return core.dieMessage("Index out of bounds");
}
return pipe(tRef.get(self.chunk[index]), core.flatMap(f), core.flatMap(updated => tRef.set(self.chunk[index], updated)));
});
//# sourceMappingURL=tArray.js.map

File diff suppressed because one or more lines are too long

41
node_modules/effect/dist/esm/internal/stm/tDeferred.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
import * as Either from "../../Either.js";
import { dual } from "../../Function.js";
import * as Option from "../../Option.js";
import * as core from "./core.js";
import * as stm from "./stm.js";
import * as tRef from "./tRef.js";
/** @internal */
const TDeferredSymbolKey = "effect/TDeferred";
/** @internal */
export const TDeferredTypeId = /*#__PURE__*/Symbol.for(TDeferredSymbolKey);
/** @internal */
const tDeferredVariance = {
/* c8 ignore next */
_A: _ => _,
/* c8 ignore next */
_E: _ => _
};
/** @internal */
class TDeferredImpl {
ref;
[TDeferredTypeId] = tDeferredVariance;
constructor(ref) {
this.ref = ref;
}
}
/** @internal */
export const _await = self => stm.flatten(stm.collect(tRef.get(self.ref), option => Option.isSome(option) ? Option.some(stm.fromEither(option.value)) : Option.none()));
/** @internal */
export const done = /*#__PURE__*/dual(2, (self, either) => core.flatMap(tRef.get(self.ref), Option.match({
onNone: () => core.zipRight(tRef.set(self.ref, Option.some(either)), core.succeed(true)),
onSome: () => core.succeed(false)
})));
/** @internal */
export const fail = /*#__PURE__*/dual(2, (self, error) => done(self, Either.left(error)));
/** @internal */
export const make = () => core.map(tRef.make(Option.none()), ref => new TDeferredImpl(ref));
/** @internal */
export const poll = self => tRef.get(self.ref);
/** @internal */
export const succeed = /*#__PURE__*/dual(2, (self, value) => done(self, Either.right(value)));
//# sourceMappingURL=tDeferred.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tDeferred.js","names":["Either","dual","Option","core","stm","tRef","TDeferredSymbolKey","TDeferredTypeId","Symbol","for","tDeferredVariance","_A","_","_E","TDeferredImpl","ref","constructor","_await","self","flatten","collect","get","option","isSome","some","fromEither","value","none","done","either","flatMap","match","onNone","zipRight","set","succeed","onSome","fail","error","left","make","map","poll","right"],"sources":["../../../../src/internal/stm/tDeferred.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,iBAAiB;AACzC,SAASC,IAAI,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B,IAAI,CAACK,MAAM,CAAC,CAAC,EACvC1B,IAAI,CAACgC,OAAO,CAAC,IAAI,CAAC,CACnB;EACHC,MAAM,EAAEA,CAAA,KAAMjC,IAAI,CAACgC,OAAO,CAAC,KAAK;CACjC,CAAC,CACH,CAAC;AAEJ;AACA,OAAO,MAAME,IAAI,gBAAGpC,IAAI,CAGtB,CAAC,EAAE,CAACiB,IAAI,EAAEoB,KAAK,KAAKV,IAAI,CAACV,IAAI,EAAElB,MAAM,CAACuC,IAAI,CAACD,KAAK,CAAC,CAAC,CAAC;AAErD;AACA,OAAO,MAAME,IAAI,GAAGA,CAAA,KAClBrC,IAAI,CAACsC,GAAG,CACNpC,IAAI,CAACmC,IAAI,CAAqCtC,MAAM,CAACyB,IAAI,EAAE,CAAC,EAC3DZ,GAAG,IAAK,IAAID,aAAa,CAACC,GAAG,CAAC,CAChC;AAEH;AACA,OAAO,MAAM2B,IAAI,GACfxB,IAA+B,IACiBb,IAAI,CAACgB,GAAG,CAACH,IAAI,CAACH,GAAG,CAAC;AAEpE;AACA,OAAO,MAAMoB,OAAO,gBAAGlC,IAAI,CAGzB,CAAC,EAAE,CAACiB,IAAI,EAAEQ,KAAK,KAAKE,IAAI,CAACV,IAAI,EAAElB,MAAM,CAAC2C,KAAK,CAACjB,KAAK,CAAC,CAAC,CAAC","ignoreList":[]}

101
node_modules/effect/dist/esm/internal/stm/tExit.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
import * as Equal from "../../Equal.js";
import { pipe } from "../../Function.js";
import * as Hash from "../../Hash.js";
import { hasProperty } from "../../Predicate.js";
import * as OpCodes from "./opCodes/tExit.js";
/** @internal */
const TExitSymbolKey = "effect/TExit";
/** @internal */
export const TExitTypeId = /*#__PURE__*/Symbol.for(TExitSymbolKey);
const variance = {
/* c8 ignore next */
_A: _ => _,
/* c8 ignore next */
_E: _ => _
};
/** @internal */
export const isExit = u => hasProperty(u, TExitTypeId);
/** @internal */
export const isFail = self => {
return self._tag === OpCodes.OP_FAIL;
};
/** @internal */
export const isDie = self => {
return self._tag === OpCodes.OP_DIE;
};
/** @internal */
export const isInterrupt = self => {
return self._tag === OpCodes.OP_INTERRUPT;
};
/** @internal */
export const isSuccess = self => {
return self._tag === OpCodes.OP_SUCCEED;
};
/** @internal */
export const isRetry = self => {
return self._tag === OpCodes.OP_RETRY;
};
/** @internal */
export const fail = error => ({
[TExitTypeId]: variance,
_tag: OpCodes.OP_FAIL,
error,
[Hash.symbol]() {
return pipe(Hash.hash(TExitSymbolKey), Hash.combine(Hash.hash(OpCodes.OP_FAIL)), Hash.combine(Hash.hash(error)), Hash.cached(this));
},
[Equal.symbol](that) {
return isExit(that) && that._tag === OpCodes.OP_FAIL && Equal.equals(error, that.error);
}
});
/** @internal */
export const die = defect => ({
[TExitTypeId]: variance,
_tag: OpCodes.OP_DIE,
defect,
[Hash.symbol]() {
return pipe(Hash.hash(TExitSymbolKey), Hash.combine(Hash.hash(OpCodes.OP_DIE)), Hash.combine(Hash.hash(defect)), Hash.cached(this));
},
[Equal.symbol](that) {
return isExit(that) && that._tag === OpCodes.OP_DIE && Equal.equals(defect, that.defect);
}
});
/** @internal */
export const interrupt = fiberId => ({
[TExitTypeId]: variance,
_tag: OpCodes.OP_INTERRUPT,
fiberId,
[Hash.symbol]() {
return pipe(Hash.hash(TExitSymbolKey), Hash.combine(Hash.hash(OpCodes.OP_INTERRUPT)), Hash.combine(Hash.hash(fiberId)), Hash.cached(this));
},
[Equal.symbol](that) {
return isExit(that) && that._tag === OpCodes.OP_INTERRUPT && Equal.equals(fiberId, that.fiberId);
}
});
/** @internal */
export const succeed = value => ({
[TExitTypeId]: variance,
_tag: OpCodes.OP_SUCCEED,
value,
[Hash.symbol]() {
return pipe(Hash.hash(TExitSymbolKey), Hash.combine(Hash.hash(OpCodes.OP_SUCCEED)), Hash.combine(Hash.hash(value)), Hash.cached(this));
},
[Equal.symbol](that) {
return isExit(that) && that._tag === OpCodes.OP_SUCCEED && Equal.equals(value, that.value);
}
});
const retryHash = /*#__PURE__*/pipe(/*#__PURE__*/Hash.hash(TExitSymbolKey), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash(OpCodes.OP_RETRY)), /*#__PURE__*/Hash.combine(/*#__PURE__*/Hash.hash("retry")));
/** @internal */
export const retry = {
[TExitTypeId]: variance,
_tag: OpCodes.OP_RETRY,
[Hash.symbol]() {
return retryHash;
},
[Equal.symbol](that) {
return isExit(that) && isRetry(that);
}
};
const void_ = /*#__PURE__*/succeed(undefined);
export { /** @internal */
void_ as void };
//# sourceMappingURL=tExit.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tExit.js","names":["Equal","pipe","Hash","hasProperty","OpCodes","TExitSymbolKey","TExitTypeId","Symbol","for","variance","_A","_","_E","isExit","u","isFail","self","_tag","OP_FAIL","isDie","OP_DIE","isInterrupt","OP_INTERRUPT","isSuccess","OP_SUCCEED","isRetry","OP_RETRY","fail","error","symbol","hash","combine","cached","that","equals","die","defect","interrupt","fiberId","succeed","value","retryHash","retry","void_","undefined","void"],"sources":["../../../../src/internal/stm/tExit.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,gBAAgB;AAEvC,SAASC,IAAI,QAAQ,mBAAmB;AACxC,OAAO,KAAKC,IAAI,MAAM,eAAe;AACrC,SAASC,WAAW,QAAQ,oBAAoB;AAEhD,OAAO,KAAKC,OAAO,MAAM,oBAAoB;AAE7C;AACA,MAAMC,cAAc,GAAG,cAAc;AAErC;AACA,OAAO,MAAMC,WAAW,gBAAGC,MAAM,CAACC,GAAG,CAACH,cAAc,CAAC;AAmBrD,MAAMI,QAAQ,GAAG;EACf;EACAC,EAAE,EAAGC,CAAQ,IAAKA,CAAC;EACnB;EACAC,EAAE,EAAGD,CAAQ,IAAKA;CACnB;AA+BD;AACA,OAAO,MAAME,MAAM,GAAIC,CAAU,IAAmCX,WAAW,CAACW,CAAC,EAAER,WAAW,CAAC;AAE/F;AACA,OAAO,MAAMS,MAAM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jC;AAED;AACA,OAAO,MAAMY,KAAK,GAAiB;EACjC,CAACpC,WAAW,GAAGG,QAAQ;EACvBQ,IAAI,EAAEb,OAAO,CAACsB,QAAQ;EACtB,CAACxB,IAAI,CAAC2B,MAAM,IAAC;IACX,OAAOY,SAAS;EAClB,CAAC;EACD,CAACzC,KAAK,CAAC6B,MAAM,EAAEI,IAAa;IAC1B,OAAOpB,MAAM,CAACoB,IAAI,CAAC,IAAIR,OAAO,CAACQ,IAAI,CAAC;EACtC;CACD;AAED,MAAMU,KAAK,gBAAgBJ,OAAO,CAACK,SAAS,CAAC;AAC7C,SACE;AACAD,KAAK,IAAIE,IAAI","ignoreList":[]}

430
node_modules/effect/dist/esm/internal/stm/tMap.js generated vendored Normal file
View File

@@ -0,0 +1,430 @@
import * as RA from "../../Array.js";
import * as Chunk from "../../Chunk.js";
import * as Equal from "../../Equal.js";
import { dual, pipe } from "../../Function.js";
import * as Hash from "../../Hash.js";
import * as HashMap from "../../HashMap.js";
import * as Option from "../../Option.js";
import { hasProperty } from "../../Predicate.js";
import * as STM from "../../STM.js";
import * as core from "./core.js";
import * as stm from "./stm.js";
import * as tArray from "./tArray.js";
import * as tRef from "./tRef.js";
/** @internal */
const TMapSymbolKey = "effect/TMap";
/** @internal */
export const TMapTypeId = /*#__PURE__*/Symbol.for(TMapSymbolKey);
const tMapVariance = {
/* c8 ignore next */
_K: _ => _,
/* c8 ignore next */
_V: _ => _
};
/** @internal */
class TMapImpl {
tBuckets;
tSize;
[TMapTypeId] = tMapVariance;
constructor(tBuckets, tSize) {
this.tBuckets = tBuckets;
this.tSize = tSize;
}
}
const isTMap = u => hasProperty(u, TMapTypeId);
/** @internal */
const InitialCapacity = 16;
const LoadFactor = 0.75;
/** @internal */
const nextPowerOfTwo = size => {
const n = -1 >>> Math.clz32(size - 1);
return n < 0 ? 1 : n + 1;
};
/** @internal */
const hash = key => {
const h = Hash.hash(key);
return h ^ h >>> 16;
};
/** @internal */
const indexOf = (k, capacity) => hash(k) & capacity - 1;
/** @internal */
const allocate = (capacity, data) => {
const buckets = Array.from({
length: capacity
}, () => Chunk.empty());
const distinct = new Map(data);
let size = 0;
for (const entry of distinct) {
const index = indexOf(entry[0], capacity);
buckets[index] = pipe(buckets[index], Chunk.prepend(entry));
size = size + 1;
}
return pipe(tArray.fromIterable(buckets), core.flatMap(buckets => pipe(tRef.make(buckets), core.flatMap(tBuckets => pipe(tRef.make(size), core.map(tSize => new TMapImpl(tBuckets, tSize)))))));
};
/** @internal */
export const empty = () => fromIterable([]);
/** @internal */
export const find = /*#__PURE__*/dual(2, (self, pf) => findSTM(self, (key, value) => {
const option = pf(key, value);
if (Option.isSome(option)) {
return core.succeed(option.value);
}
return core.fail(Option.none());
}));
/** @internal */
export const findSTM = /*#__PURE__*/dual(2, (self, f) => reduceSTM(self, Option.none(), (acc, value, key) => Option.isNone(acc) ? core.matchSTM(f(key, value), {
onFailure: Option.match({
onNone: () => stm.succeedNone,
onSome: core.fail
}),
onSuccess: stm.succeedSome
}) : STM.succeed(acc)));
/** @internal */
export const findAll = /*#__PURE__*/dual(2, (self, pf) => findAllSTM(self, (key, value) => {
const option = pf(key, value);
if (Option.isSome(option)) {
return core.succeed(option.value);
}
return core.fail(Option.none());
}));
/** @internal */
export const findAllSTM = /*#__PURE__*/dual(2, (self, pf) => core.map(reduceSTM(self, Chunk.empty(), (acc, value, key) => core.matchSTM(pf(key, value), {
onFailure: Option.match({
onNone: () => core.succeed(acc),
onSome: core.fail
}),
onSuccess: a => core.succeed(Chunk.append(acc, a))
})), a => Array.from(a)));
/** @internal */
export const forEach = /*#__PURE__*/dual(2, (self, f) => reduceSTM(self, void 0, (_, value, key) => stm.asVoid(f(key, value))));
/** @internal */
export const fromIterable = iterable => stm.suspend(() => {
const data = Chunk.fromIterable(iterable);
const capacity = data.length < InitialCapacity ? InitialCapacity : nextPowerOfTwo(data.length);
return allocate(capacity, data);
});
/** @internal */
export const get = /*#__PURE__*/dual(2, (self, key) => core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const index = indexOf(key, buckets.chunk.length);
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
return pipe(Chunk.findFirst(bucket, entry => Equal.equals(entry[0])(key)), Option.map(entry => entry[1]));
}));
/** @internal */
export const getOrElse = /*#__PURE__*/dual(3, (self, key, fallback) => core.map(get(self, key), Option.getOrElse(fallback)));
/** @internal */
export const has = /*#__PURE__*/dual(2, (self, key) => core.map(get(self, key), Option.isSome));
/** @internal */
export const isEmpty = self => core.map(tRef.get(self.tSize), size => size === 0);
/** @internal */
export const keys = self => core.map(toReadonlyArray(self), RA.map(entry => entry[0]));
/** @internal */
export const make = (...entries) => fromIterable(entries);
/** @internal */
export const merge = /*#__PURE__*/dual(4, (self, key, value, f) => core.flatMap(get(self, key), Option.match({
onNone: () => stm.as(set(self, key, value), value),
onSome: v0 => {
const v1 = f(v0, value);
return stm.as(set(self, key, v1), v1);
}
})));
/** @internal */
export const reduce = /*#__PURE__*/dual(3, (self, zero, f) => core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
let result = zero;
let index = 0;
while (index < buckets.chunk.length) {
const bucket = buckets.chunk[index];
const items = tRef.unsafeGet(bucket, journal);
result = Chunk.reduce(items, result, (acc, entry) => f(acc, entry[1], entry[0]));
index = index + 1;
}
return result;
}));
/** @internal */
export const reduceSTM = /*#__PURE__*/dual(3, (self, zero, f) => core.flatMap(toReadonlyArray(self), stm.reduce(zero, (acc, entry) => f(acc, entry[1], entry[0]))));
/** @internal */
export const remove = /*#__PURE__*/dual(2, (self, key) => core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const index = indexOf(key, buckets.chunk.length);
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const [toRemove, toRetain] = Chunk.partition(bucket, entry => Equal.equals(entry[1], key));
if (Chunk.isNonEmpty(toRemove)) {
const currentSize = tRef.unsafeGet(self.tSize, journal);
tRef.unsafeSet(buckets.chunk[index], toRetain, journal);
tRef.unsafeSet(self.tSize, currentSize - 1, journal);
}
}));
/** @internal */
export const removeAll = /*#__PURE__*/dual(2, (self, keys) => core.effect(journal => {
const iterator = keys[Symbol.iterator]();
let next;
while ((next = iterator.next()) && !next.done) {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const index = indexOf(next.value, buckets.chunk.length);
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const [toRemove, toRetain] = Chunk.partition(bucket, entry => Equal.equals(next.value)(entry[0]));
if (Chunk.isNonEmpty(toRemove)) {
const currentSize = tRef.unsafeGet(self.tSize, journal);
tRef.unsafeSet(buckets.chunk[index], toRetain, journal);
tRef.unsafeSet(self.tSize, currentSize - 1, journal);
}
}
}));
/** @internal */
export const removeIf = /*#__PURE__*/dual(args => isTMap(args[0]), (self, predicate, options) => core.effect(journal => {
const discard = options?.discard === true;
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const removed = [];
let index = 0;
let newSize = 0;
while (index < capacity) {
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const iterator = bucket[Symbol.iterator]();
let next;
let newBucket = Chunk.empty();
while ((next = iterator.next()) && !next.done) {
const [k, v] = next.value;
if (!predicate(k, v)) {
newBucket = Chunk.prepend(newBucket, next.value);
newSize = newSize + 1;
} else {
if (!discard) {
removed.push([k, v]);
}
}
}
tRef.unsafeSet(buckets.chunk[index], newBucket, journal);
index = index + 1;
}
tRef.unsafeSet(self.tSize, newSize, journal);
if (!discard) {
return removed;
}
}));
/** @internal */
export const retainIf = /*#__PURE__*/dual(args => isTMap(args[0]), (self, predicate, options) => removeIf(self, (key, value) => !predicate(key, value), options));
/** @internal */
export const set = /*#__PURE__*/dual(3, (self, key, value) => {
const resize = (journal, buckets) => {
const capacity = buckets.chunk.length;
const newCapacity = capacity << 1;
const newBuckets = Array.from({
length: newCapacity
}, () => Chunk.empty());
let index = 0;
while (index < capacity) {
const pairs = tRef.unsafeGet(buckets.chunk[index], journal);
const iterator = pairs[Symbol.iterator]();
let next;
while ((next = iterator.next()) && !next.done) {
const newIndex = indexOf(next.value[0], newCapacity);
newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], next.value);
}
index = index + 1;
}
// insert new pair
const newIndex = indexOf(key, newCapacity);
newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], [key, value]);
const newArray = [];
index = 0;
while (index < newCapacity) {
newArray[index] = new tRef.TRefImpl(newBuckets[index]);
index = index + 1;
}
const newTArray = new tArray.TArrayImpl(newArray);
tRef.unsafeSet(self.tBuckets, newTArray, journal);
};
return core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const index = indexOf(key, capacity);
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const shouldUpdate = Chunk.some(bucket, entry => Equal.equals(key)(entry[0]));
if (shouldUpdate) {
const newBucket = Chunk.map(bucket, entry => Equal.equals(key)(entry[0]) ? [key, value] : entry);
tRef.unsafeSet(buckets.chunk[index], newBucket, journal);
} else {
const newSize = tRef.unsafeGet(self.tSize, journal) + 1;
tRef.unsafeSet(self.tSize, newSize, journal);
if (capacity * LoadFactor < newSize) {
resize(journal, buckets);
} else {
const newBucket = Chunk.prepend(bucket, [key, value]);
tRef.unsafeSet(buckets.chunk[index], newBucket, journal);
}
}
});
});
/** @internal */
export const setIfAbsent = /*#__PURE__*/dual(3, (self, key, value) => core.flatMap(get(self, key), Option.match({
onNone: () => set(self, key, value),
onSome: () => stm.void
})));
/** @internal */
export const size = self => tRef.get(self.tSize);
/** @internal */
export const takeFirst = /*#__PURE__*/dual(2, (self, pf) => pipe(core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const size = tRef.unsafeGet(self.tSize, journal);
let result = Option.none();
let index = 0;
while (index < capacity && Option.isNone(result)) {
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const recreate = Chunk.some(bucket, entry => Option.isSome(pf(entry[0], entry[1])));
if (recreate) {
const iterator = bucket[Symbol.iterator]();
let newBucket = Chunk.empty();
let next;
while ((next = iterator.next()) && !next.done && Option.isNone(result)) {
const option = pf(next.value[0], next.value[1]);
if (Option.isSome(option) && Option.isNone(result)) {
result = option;
} else {
newBucket = Chunk.prepend(newBucket, next.value);
}
}
tRef.unsafeSet(buckets.chunk[index], newBucket, journal);
}
index = index + 1;
}
if (Option.isSome(result)) {
tRef.unsafeSet(self.tSize, size - 1, journal);
}
return result;
}), stm.collect(option => Option.isSome(option) ? Option.some(option.value) : Option.none())));
/** @internal */
export const takeFirstSTM = /*#__PURE__*/dual(2, (self, pf) => pipe(findSTM(self, (key, value) => core.map(pf(key, value), a => [key, a])), stm.collect(option => Option.isSome(option) ? Option.some(option.value) : Option.none()), core.flatMap(entry => stm.as(remove(self, entry[0]), entry[1]))));
/** @internal */
export const takeSome = /*#__PURE__*/dual(2, (self, pf) => pipe(core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const builder = [];
let newSize = 0;
let index = 0;
while (index < capacity) {
const bucket = tRef.unsafeGet(buckets.chunk[index], journal);
const recreate = Chunk.some(bucket, entry => Option.isSome(pf(entry[0], entry[1])));
if (recreate) {
const iterator = bucket[Symbol.iterator]();
let newBucket = Chunk.empty();
let next;
while ((next = iterator.next()) && !next.done) {
const option = pf(next.value[0], next.value[1]);
if (Option.isSome(option)) {
builder.push(option.value);
} else {
newBucket = Chunk.prepend(newBucket, next.value);
newSize = newSize + 1;
}
}
tRef.unsafeSet(buckets.chunk[index], newBucket, journal);
} else {
newSize = newSize + bucket.length;
}
index = index + 1;
}
tRef.unsafeSet(self.tSize, newSize, journal);
if (builder.length > 0) {
return Option.some(builder);
}
return Option.none();
}), stm.collect(option => Option.isSome(option) ? Option.some(option.value) : Option.none())));
/** @internal */
export const takeSomeSTM = /*#__PURE__*/dual(2, (self, pf) => pipe(findAllSTM(self, (key, value) => core.map(pf(key, value), a => [key, a])), core.map(chunk => RA.isNonEmptyArray(chunk) ? Option.some(chunk) : Option.none()), stm.collect(option => Option.isSome(option) ? Option.some(option.value) : Option.none()), core.flatMap(entries => stm.as(removeAll(self, entries.map(entry => entry[0])), RA.map(entries, entry => entry[1])))));
const toReadonlyArray = self => core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const builder = [];
let index = 0;
while (index < capacity) {
const bucket = buckets.chunk[index];
for (const entry of tRef.unsafeGet(bucket, journal)) {
builder.push(entry);
}
index = index + 1;
}
return builder;
});
/** @internal */
export const toChunk = self => reduce(self, Chunk.empty(), (acc, value, key) => Chunk.append(acc, [key, value]));
/** @internal */
export const toHashMap = self => reduce(self, HashMap.empty(), (acc, value, key) => pipe(acc, HashMap.set(key, value)));
/** @internal */
export const toArray = self => reduce(self, [], (acc, value, key) => {
acc.unshift([key, value]);
return acc;
});
/** @internal */
export const toMap = self => reduce(self, new Map(), (acc, value, key) => acc.set(key, value));
/** @internal */
export const transform = /*#__PURE__*/dual(2, (self, f) => core.effect(journal => {
const buckets = pipe(self.tBuckets, tRef.unsafeGet(journal));
const capacity = buckets.chunk.length;
const newBuckets = Array.from({
length: capacity
}, () => Chunk.empty());
let newSize = 0;
let index = 0;
while (index < capacity) {
const bucket = buckets.chunk[index];
const pairs = tRef.unsafeGet(bucket, journal);
const iterator = pairs[Symbol.iterator]();
let next;
while ((next = iterator.next()) && !next.done) {
const newPair = f(next.value[0], next.value[1]);
const index = indexOf(newPair[0], capacity);
const newBucket = newBuckets[index];
if (!Chunk.some(newBucket, entry => Equal.equals(entry[0], newPair[0]))) {
newBuckets[index] = Chunk.prepend(newBucket, newPair);
newSize = newSize + 1;
}
}
index = index + 1;
}
index = 0;
while (index < capacity) {
tRef.unsafeSet(buckets.chunk[index], newBuckets[index], journal);
index = index + 1;
}
tRef.unsafeSet(self.tSize, newSize, journal);
}));
/** @internal */
export const transformSTM = /*#__PURE__*/dual(2, (self, f) => pipe(core.flatMap(toReadonlyArray(self), stm.forEach(entry => f(entry[0], entry[1]))), core.flatMap(newData => core.effect(journal => {
const buckets = tRef.unsafeGet(self.tBuckets, journal);
const capacity = buckets.chunk.length;
const newBuckets = Array.from({
length: capacity
}, () => Chunk.empty());
const iterator = newData[Symbol.iterator]();
let newSize = 0;
let next;
while ((next = iterator.next()) && !next.done) {
const index = indexOf(next.value[0], capacity);
const newBucket = newBuckets[index];
if (!Chunk.some(newBucket, entry => Equal.equals(entry[0])(next.value[0]))) {
newBuckets[index] = Chunk.prepend(newBucket, next.value);
newSize = newSize + 1;
}
}
let index = 0;
while (index < capacity) {
tRef.unsafeSet(buckets.chunk[index], newBuckets[index], journal);
index = index + 1;
}
tRef.unsafeSet(self.tSize, newSize, journal);
}))));
/** @internal */
export const transformValues = /*#__PURE__*/dual(2, (self, f) => transform(self, (key, value) => [key, f(value)]));
/** @internal */
export const transformValuesSTM = /*#__PURE__*/dual(2, (self, f) => transformSTM(self, (key, value) => core.map(f(value), value => [key, value])));
/** @internal */
export const updateWith = /*#__PURE__*/dual(3, (self, key, f) => core.flatMap(get(self, key), option => Option.match(f(option), {
onNone: () => stm.as(remove(self, key), Option.none()),
onSome: value => stm.as(set(self, key, value), Option.some(value))
})));
/** @internal */
export const values = self => core.map(toReadonlyArray(self), RA.map(entry => entry[1]));
//# sourceMappingURL=tMap.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,143 @@
import * as Arr from "../../Array.js";
import * as Chunk from "../../Chunk.js";
import { dual, pipe } from "../../Function.js";
import * as Option from "../../Option.js";
import * as SortedMap from "../../SortedMap.js";
import * as core from "./core.js";
import * as tRef from "./tRef.js";
/** @internal */
const TPriorityQueueSymbolKey = "effect/TPriorityQueue";
/** @internal */
export const TPriorityQueueTypeId = /*#__PURE__*/Symbol.for(TPriorityQueueSymbolKey);
const tPriorityQueueVariance = {
/* c8 ignore next */
_A: _ => _
};
/** @internal */
export class TPriorityQueueImpl {
ref;
[TPriorityQueueTypeId] = tPriorityQueueVariance;
constructor(ref) {
this.ref = ref;
}
}
/** @internal */
export const empty = order => pipe(tRef.make(SortedMap.empty(order)), core.map(ref => new TPriorityQueueImpl(ref)));
/** @internal */
export const fromIterable = order => iterable => pipe(tRef.make(Arr.fromIterable(iterable).reduce((map, value) => pipe(map, SortedMap.set(value, pipe(map, SortedMap.get(value), Option.match({
onNone: () => Arr.of(value),
onSome: Arr.prepend(value)
})))), SortedMap.empty(order))), core.map(ref => new TPriorityQueueImpl(ref)));
/** @internal */
export const isEmpty = self => core.map(tRef.get(self.ref), SortedMap.isEmpty);
/** @internal */
export const isNonEmpty = self => core.map(tRef.get(self.ref), SortedMap.isNonEmpty);
/** @internal */
export const make = order => (...elements) => fromIterable(order)(elements);
/** @internal */
export const offer = /*#__PURE__*/dual(2, (self, value) => tRef.update(self.ref, map => SortedMap.set(map, value, Option.match(SortedMap.get(map, value), {
onNone: () => Arr.of(value),
onSome: Arr.prepend(value)
}))));
/** @internal */
export const offerAll = /*#__PURE__*/dual(2, (self, values) => tRef.update(self.ref, map => Arr.fromIterable(values).reduce((map, value) => SortedMap.set(map, value, Option.match(SortedMap.get(map, value), {
onNone: () => Arr.of(value),
onSome: Arr.prepend(value)
})), map)));
/** @internal */
export const peek = self => core.withSTMRuntime(runtime => {
const map = tRef.unsafeGet(self.ref, runtime.journal);
return Option.match(SortedMap.headOption(map), {
onNone: () => core.retry,
onSome: elements => core.succeed(elements[0])
});
});
/** @internal */
export const peekOption = self => tRef.modify(self.ref, map => [Option.map(SortedMap.headOption(map), elements => elements[0]), map]);
/** @internal */
export const removeIf = /*#__PURE__*/dual(2, (self, predicate) => retainIf(self, a => !predicate(a)));
/** @internal */
export const retainIf = /*#__PURE__*/dual(2, (self, predicate) => tRef.update(self.ref, map => SortedMap.reduce(map, SortedMap.empty(SortedMap.getOrder(map)), (map, value, key) => {
const filtered = Arr.filter(value, predicate);
return filtered.length > 0 ? SortedMap.set(map, key, filtered) : SortedMap.remove(map, key);
})));
/** @internal */
export const size = self => tRef.modify(self.ref, map => [SortedMap.reduce(map, 0, (n, as) => n + as.length), map]);
/** @internal */
export const take = self => core.withSTMRuntime(runtime => {
const map = tRef.unsafeGet(self.ref, runtime.journal);
return Option.match(SortedMap.headOption(map), {
onNone: () => core.retry,
onSome: values => {
const head = values[1][0];
const tail = values[1].slice(1);
tRef.unsafeSet(self.ref, tail.length > 0 ? SortedMap.set(map, head, tail) : SortedMap.remove(map, head), runtime.journal);
return core.succeed(head);
}
});
});
/** @internal */
export const takeAll = self => tRef.modify(self.ref, map => {
const builder = [];
for (const entry of map) {
for (const value of entry[1]) {
builder.push(value);
}
}
return [builder, SortedMap.empty(SortedMap.getOrder(map))];
});
/** @internal */
export const takeOption = self => core.effect(journal => {
const map = pipe(self.ref, tRef.unsafeGet(journal));
return Option.match(SortedMap.headOption(map), {
onNone: () => Option.none(),
onSome: ([key, value]) => {
const tail = value.slice(1);
tRef.unsafeSet(self.ref, tail.length > 0 ? SortedMap.set(map, key, tail) : SortedMap.remove(map, key), journal);
return Option.some(value[0]);
}
});
});
/** @internal */
export const takeUpTo = /*#__PURE__*/dual(2, (self, n) => tRef.modify(self.ref, map => {
const builder = [];
const iterator = map[Symbol.iterator]();
let updated = map;
let index = 0;
let next;
while ((next = iterator.next()) && !next.done && index < n) {
const [key, value] = next.value;
const [left, right] = pipe(value, Arr.splitAt(n - index));
for (const value of left) {
builder.push(value);
}
if (right.length > 0) {
updated = SortedMap.set(updated, key, right);
} else {
updated = SortedMap.remove(updated, key);
}
index = index + left.length;
}
return [builder, updated];
}));
/** @internal */
export const toChunk = self => tRef.modify(self.ref, map => {
const builder = [];
for (const entry of map) {
for (const value of entry[1]) {
builder.push(value);
}
}
return [Chunk.unsafeFromArray(builder), map];
});
/** @internal */
export const toArray = self => tRef.modify(self.ref, map => {
const builder = [];
for (const entry of map) {
for (const value of entry[1]) {
builder.push(value);
}
}
return [builder, map];
});
//# sourceMappingURL=tPriorityQueue.js.map

File diff suppressed because one or more lines are too long

376
node_modules/effect/dist/esm/internal/stm/tPubSub.js generated vendored Normal file
View File

@@ -0,0 +1,376 @@
import * as RA from "../../Array.js";
import * as Effect from "../../Effect.js";
import { dual, identity, pipe } from "../../Function.js";
import * as HashSet from "../../HashSet.js";
import * as Option from "../../Option.js";
import * as core from "./core.js";
import * as OpCodes from "./opCodes/strategy.js";
import * as stm from "./stm.js";
import * as tQueue from "./tQueue.js";
import * as tRef from "./tRef.js";
/** @internal */
const TPubSubSymbolKey = "effect/TPubSub";
/** @internal */
export const TPubSubTypeId = /*#__PURE__*/Symbol.for(TPubSubSymbolKey);
const AbsentValue = /*#__PURE__*/Symbol.for("effect/TPubSub/AbsentValue");
/** @internal */
export const makeNode = (head, subscribers, tail) => ({
head,
subscribers,
tail
});
/** @internal */
class TPubSubImpl {
pubsubSize;
publisherHead;
publisherTail;
requestedCapacity;
strategy;
subscriberCount;
subscribers;
[TPubSubTypeId] = {
_A: _ => _
};
[tQueue.TEnqueueTypeId] = tQueue.tEnqueueVariance;
constructor(pubsubSize, publisherHead, publisherTail, requestedCapacity, strategy, subscriberCount, subscribers) {
this.pubsubSize = pubsubSize;
this.publisherHead = publisherHead;
this.publisherTail = publisherTail;
this.requestedCapacity = requestedCapacity;
this.strategy = strategy;
this.subscriberCount = subscriberCount;
this.subscribers = subscribers;
}
isShutdown = /*#__PURE__*/core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
return currentPublisherTail === undefined;
});
awaitShutdown = /*#__PURE__*/core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.void : core.retry);
capacity() {
return this.requestedCapacity;
}
size = /*#__PURE__*/core.withSTMRuntime(runtime => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal);
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(tRef.unsafeGet(this.pubsubSize, runtime.journal));
});
isEmpty = /*#__PURE__*/core.map(this.size, size => size === 0);
isFull = /*#__PURE__*/core.map(this.size, size => size === this.capacity());
offer(value) {
return core.withSTMRuntime(runtime => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal);
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId);
}
const currentSubscriberCount = tRef.unsafeGet(this.subscriberCount, runtime.journal);
if (currentSubscriberCount === 0) {
return core.succeed(true);
}
const currentPubSubSize = tRef.unsafeGet(this.pubsubSize, runtime.journal);
if (currentPubSubSize < this.requestedCapacity) {
const updatedPublisherTail = new tRef.TRefImpl(void 0);
const updatedNode = makeNode(value, currentSubscriberCount, updatedPublisherTail);
tRef.unsafeSet(currentPublisherTail, updatedNode, runtime.journal);
tRef.unsafeSet(this.publisherTail, updatedPublisherTail, runtime.journal);
tRef.unsafeSet(this.pubsubSize, currentPubSubSize + 1, runtime.journal);
return core.succeed(true);
}
switch (this.strategy._tag) {
case OpCodes.OP_BACKPRESSURE_STRATEGY:
{
return core.retry;
}
case OpCodes.OP_DROPPING_STRATEGY:
{
return core.succeed(false);
}
case OpCodes.OP_SLIDING_STRATEGY:
{
if (this.requestedCapacity > 0) {
let currentPublisherHead = tRef.unsafeGet(this.publisherHead, runtime.journal);
let loop = true;
while (loop) {
const node = tRef.unsafeGet(currentPublisherHead, runtime.journal);
if (node === undefined) {
return core.retry;
}
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
const updatedNode = makeNode(AbsentValue, node.subscribers, node.tail);
tRef.unsafeSet(currentPublisherHead, updatedNode, runtime.journal);
tRef.unsafeSet(this.publisherHead, tail, runtime.journal);
loop = false;
} else {
currentPublisherHead = tail;
}
}
}
const updatedPublisherTail = new tRef.TRefImpl(void 0);
const updatedNode = makeNode(value, currentSubscriberCount, updatedPublisherTail);
tRef.unsafeSet(currentPublisherTail, updatedNode, runtime.journal);
tRef.unsafeSet(this.publisherTail, updatedPublisherTail, runtime.journal);
return core.succeed(true);
}
}
});
}
offerAll(iterable) {
return core.map(stm.forEach(iterable, a => this.offer(a)), RA.every(identity));
}
shutdown = /*#__PURE__*/core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
if (currentPublisherTail !== undefined) {
tRef.unsafeSet(this.publisherTail, void 0, journal);
const currentSubscribers = tRef.unsafeGet(this.subscribers, journal);
HashSet.forEach(currentSubscribers, subscriber => {
tRef.unsafeSet(subscriber, void 0, journal);
});
tRef.unsafeSet(this.subscribers, HashSet.empty(), journal);
}
});
}
/** @internal */
class TPubSubSubscriptionImpl {
pubsubSize;
publisherHead;
requestedCapacity;
subscriberHead;
subscriberCount;
subscribers;
[TPubSubTypeId] = TPubSubTypeId;
[tQueue.TDequeueTypeId] = tQueue.tDequeueVariance;
constructor(pubsubSize, publisherHead, requestedCapacity, subscriberHead, subscriberCount, subscribers) {
this.pubsubSize = pubsubSize;
this.publisherHead = publisherHead;
this.requestedCapacity = requestedCapacity;
this.subscriberHead = subscriberHead;
this.subscriberCount = subscriberCount;
this.subscribers = subscribers;
}
isShutdown = /*#__PURE__*/core.effect(journal => {
const currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal);
return currentSubscriberHead === undefined;
});
awaitShutdown = /*#__PURE__*/core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.void : core.retry);
capacity() {
return this.requestedCapacity;
}
size = /*#__PURE__*/core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let loop = true;
let size = 0;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
loop = false;
} else {
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
size = size + 1;
if (size >= Number.MAX_SAFE_INTEGER) {
loop = false;
}
}
currentSubscriberHead = tail;
}
}
return core.succeed(size);
});
isEmpty = /*#__PURE__*/core.map(this.size, size => size === 0);
isFull = /*#__PURE__*/core.map(this.size, size => size === this.capacity());
peek = /*#__PURE__*/core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let value = AbsentValue;
let loop = true;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
return core.retry;
}
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
value = head;
loop = false;
} else {
currentSubscriberHead = tail;
}
}
return core.succeed(value);
});
peekOption = /*#__PURE__*/core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let value = Option.none();
let loop = true;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
value = Option.none();
loop = false;
} else {
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
value = Option.some(head);
loop = false;
} else {
currentSubscriberHead = tail;
}
}
}
return core.succeed(value);
});
shutdown = /*#__PURE__*/core.effect(journal => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal);
if (currentSubscriberHead !== undefined) {
tRef.unsafeSet(this.subscriberHead, void 0, journal);
let loop = true;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, journal);
if (node === undefined) {
loop = false;
} else {
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
const subscribers = node.subscribers;
if (subscribers === 1) {
const size = tRef.unsafeGet(this.pubsubSize, journal);
const updatedNode = makeNode(AbsentValue, 0, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, journal);
tRef.unsafeSet(this.publisherHead, tail, journal);
tRef.unsafeSet(this.pubsubSize, size - 1, journal);
} else {
const updatedNode = makeNode(head, subscribers - 1, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, journal);
}
}
currentSubscriberHead = tail;
}
}
const currentSubscriberCount = tRef.unsafeGet(this.subscriberCount, journal);
tRef.unsafeSet(this.subscriberCount, currentSubscriberCount - 1, journal);
tRef.unsafeSet(this.subscribers, HashSet.remove(tRef.unsafeGet(this.subscribers, journal), this.subscriberHead), journal);
}
});
take = /*#__PURE__*/core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let value = AbsentValue;
let loop = true;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
return core.retry;
}
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
const subscribers = node.subscribers;
if (subscribers === 1) {
const size = tRef.unsafeGet(this.pubsubSize, runtime.journal);
const updatedNode = makeNode(AbsentValue, 0, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, runtime.journal);
tRef.unsafeSet(this.publisherHead, tail, runtime.journal);
tRef.unsafeSet(this.pubsubSize, size - 1, runtime.journal);
} else {
const updatedNode = makeNode(head, subscribers - 1, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, runtime.journal);
}
tRef.unsafeSet(this.subscriberHead, tail, runtime.journal);
value = head;
loop = false;
} else {
currentSubscriberHead = tail;
}
}
return core.succeed(value);
});
takeAll = /*#__PURE__*/this.takeUpTo(Number.POSITIVE_INFINITY);
takeUpTo(max) {
return core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
const builder = [];
let n = 0;
while (n !== max) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
n = max;
} else {
const head = node.head;
const tail = node.tail;
if (head !== AbsentValue) {
const subscribers = node.subscribers;
if (subscribers === 1) {
const size = tRef.unsafeGet(this.pubsubSize, runtime.journal);
const updatedNode = makeNode(AbsentValue, 0, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, runtime.journal);
tRef.unsafeSet(this.publisherHead, tail, runtime.journal);
tRef.unsafeSet(this.pubsubSize, size - 1, runtime.journal);
} else {
const updatedNode = makeNode(head, subscribers - 1, tail);
tRef.unsafeSet(currentSubscriberHead, updatedNode, runtime.journal);
}
builder.push(head);
n = n + 1;
}
currentSubscriberHead = tail;
}
}
tRef.unsafeSet(this.subscriberHead, currentSubscriberHead, runtime.journal);
return core.succeed(builder);
});
}
}
/** @internal */
const makeTPubSub = (requestedCapacity, strategy) => pipe(stm.all([tRef.make(void 0), tRef.make(0)]), core.flatMap(([empty, pubsubSize]) => pipe(stm.all([tRef.make(empty), tRef.make(empty), tRef.make(0), tRef.make(HashSet.empty())]), core.map(([publisherHead, publisherTail, subscriberCount, subscribers]) => new TPubSubImpl(pubsubSize, publisherHead, publisherTail, requestedCapacity, strategy, subscriberCount, subscribers)))));
const makeSubscription = (pubsubSize, publisherHead, publisherTail, requestedCapacity, subscriberCount, subscribers) => pipe(tRef.get(publisherTail), core.flatMap(currentPublisherTail => pipe(stm.all([tRef.make(currentPublisherTail), tRef.get(subscriberCount), tRef.get(subscribers)]), stm.tap(([_, currentSubscriberCount]) => pipe(subscriberCount, tRef.set(currentSubscriberCount + 1))), stm.tap(([subscriberHead, _, currentSubscribers]) => pipe(subscribers, tRef.set(pipe(currentSubscribers, HashSet.add(subscriberHead))))), core.map(([subscriberHead]) => new TPubSubSubscriptionImpl(pubsubSize, publisherHead, requestedCapacity, subscriberHead, subscriberCount, subscribers)))));
/** @internal */
export const awaitShutdown = self => self.awaitShutdown;
/** @internal */
export const bounded = requestedCapacity => makeTPubSub(requestedCapacity, tQueue.BackPressure);
/** @internal */
export const capacity = self => self.capacity();
/** @internal */
export const dropping = requestedCapacity => makeTPubSub(requestedCapacity, tQueue.Dropping);
/** @internal */
export const isEmpty = self => self.isEmpty;
/** @internal */
export const isFull = self => self.isFull;
/** @internal */
export const isShutdown = self => self.isShutdown;
/** @internal */
export const publish = /*#__PURE__*/dual(2, (self, value) => self.offer(value));
/** @internal */
export const publishAll = /*#__PURE__*/dual(2, (self, iterable) => self.offerAll(iterable));
/** @internal */
export const size = self => self.size;
/** @internal */
export const shutdown = self => self.shutdown;
/** @internal */
export const sliding = requestedCapacity => makeTPubSub(requestedCapacity, tQueue.Sliding);
/** @internal */
export const subscribe = self => makeSubscription(self.pubsubSize, self.publisherHead, self.publisherTail, self.requestedCapacity, self.subscriberCount, self.subscribers);
/** @internal */
export const subscribeScoped = self => Effect.acquireRelease(subscribe(self), dequeue => tQueue.shutdown(dequeue));
/** @internal */
export const unbounded = () => makeTPubSub(Number.MAX_SAFE_INTEGER, tQueue.Dropping);
//# sourceMappingURL=tPubSub.js.map

File diff suppressed because one or more lines are too long

258
node_modules/effect/dist/esm/internal/stm/tQueue.js generated vendored Normal file
View File

@@ -0,0 +1,258 @@
import * as RA from "../../Array.js";
import * as Chunk from "../../Chunk.js";
import { dual, pipe } from "../../Function.js";
import * as Option from "../../Option.js";
import { hasProperty } from "../../Predicate.js";
import * as core from "./core.js";
import * as OpCodes from "./opCodes/strategy.js";
import * as stm from "./stm.js";
import * as tRef from "./tRef.js";
const TEnqueueSymbolKey = "effect/TQueue/TEnqueue";
/** @internal */
export const TEnqueueTypeId = /*#__PURE__*/Symbol.for(TEnqueueSymbolKey);
const TDequeueSymbolKey = "effect/TQueue/TDequeue";
/** @internal */
export const TDequeueTypeId = /*#__PURE__*/Symbol.for(TDequeueSymbolKey);
/** @internal */
export const BackPressure = {
_tag: OpCodes.OP_BACKPRESSURE_STRATEGY
};
/** @internal */
export const Dropping = {
_tag: OpCodes.OP_DROPPING_STRATEGY
};
/** @internal */
export const Sliding = {
_tag: OpCodes.OP_SLIDING_STRATEGY
};
/** @internal */
export const tDequeueVariance = {
/* c8 ignore next */
_Out: _ => _
};
/** @internal */
export const tEnqueueVariance = {
/* c8 ignore next */
_In: _ => _
};
class TQueueImpl {
ref;
requestedCapacity;
strategy;
[TDequeueTypeId] = tDequeueVariance;
[TEnqueueTypeId] = tEnqueueVariance;
constructor(ref, requestedCapacity, strategy) {
this.ref = ref;
this.requestedCapacity = requestedCapacity;
this.strategy = strategy;
}
capacity() {
return this.requestedCapacity;
}
size = /*#__PURE__*/core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(queue.length);
});
isFull = /*#__PURE__*/core.map(this.size, size => size === this.requestedCapacity);
isEmpty = /*#__PURE__*/core.map(this.size, size => size === 0);
shutdown = /*#__PURE__*/core.withSTMRuntime(runtime => {
tRef.unsafeSet(this.ref, void 0, runtime.journal);
return stm.void;
});
isShutdown = /*#__PURE__*/core.effect(journal => {
const queue = tRef.unsafeGet(this.ref, journal);
return queue === undefined;
});
awaitShutdown = /*#__PURE__*/core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.void : core.retry);
offer(value) {
return core.withSTMRuntime(runtime => {
const queue = pipe(this.ref, tRef.unsafeGet(runtime.journal));
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
if (queue.length < this.requestedCapacity) {
queue.push(value);
tRef.unsafeSet(this.ref, queue, runtime.journal);
return core.succeed(true);
}
switch (this.strategy._tag) {
case OpCodes.OP_BACKPRESSURE_STRATEGY:
{
return core.retry;
}
case OpCodes.OP_DROPPING_STRATEGY:
{
return core.succeed(false);
}
case OpCodes.OP_SLIDING_STRATEGY:
{
if (queue.length === 0) {
return core.succeed(true);
}
queue.shift();
queue.push(value);
tRef.unsafeSet(this.ref, queue, runtime.journal);
return core.succeed(true);
}
}
});
}
offerAll(iterable) {
return core.withSTMRuntime(runtime => {
const as = Array.from(iterable);
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
if (queue.length + as.length <= this.requestedCapacity) {
tRef.unsafeSet(this.ref, [...queue, ...as], runtime.journal);
return core.succeed(true);
}
switch (this.strategy._tag) {
case OpCodes.OP_BACKPRESSURE_STRATEGY:
{
return core.retry;
}
case OpCodes.OP_DROPPING_STRATEGY:
{
const forQueue = as.slice(0, this.requestedCapacity - queue.length);
tRef.unsafeSet(this.ref, [...queue, ...forQueue], runtime.journal);
return core.succeed(false);
}
case OpCodes.OP_SLIDING_STRATEGY:
{
const forQueue = as.slice(0, this.requestedCapacity - queue.length);
const toDrop = queue.length + forQueue.length - this.requestedCapacity;
const newQueue = queue.slice(toDrop);
tRef.unsafeSet(this.ref, [...newQueue, ...forQueue], runtime.journal);
return core.succeed(true);
}
}
});
}
peek = /*#__PURE__*/core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
if (queue.length === 0) {
return core.retry;
}
return core.succeed(queue[0]);
});
peekOption = /*#__PURE__*/core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(Option.fromNullable(queue[0]));
});
take = /*#__PURE__*/core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
if (queue.length === 0) {
return core.retry;
}
const dequeued = queue.shift();
tRef.unsafeSet(this.ref, queue, runtime.journal);
return core.succeed(dequeued);
});
takeAll = /*#__PURE__*/core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
tRef.unsafeSet(this.ref, [], runtime.journal);
return core.succeed(queue);
});
takeUpTo(max) {
return core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
const [toTake, remaining] = Chunk.splitAt(Chunk.unsafeFromArray(queue), max);
tRef.unsafeSet(this.ref, Array.from(remaining), runtime.journal);
return core.succeed(Array.from(toTake));
});
}
}
/** @internal */
export const isTQueue = u => {
return isTEnqueue(u) && isTDequeue(u);
};
/** @internal */
export const isTEnqueue = u => hasProperty(u, TEnqueueTypeId);
/** @internal */
export const isTDequeue = u => hasProperty(u, TDequeueTypeId);
/** @internal */
export const awaitShutdown = self => self.awaitShutdown;
/** @internal */
export const bounded = requestedCapacity => makeQueue(requestedCapacity, BackPressure);
/** @internal */
export const capacity = self => {
return self.capacity();
};
/** @internal */
export const dropping = requestedCapacity => makeQueue(requestedCapacity, Dropping);
/** @internal */
export const isEmpty = self => self.isEmpty;
/** @internal */
export const isFull = self => self.isFull;
/** @internal */
export const isShutdown = self => self.isShutdown;
/** @internal */
export const offer = /*#__PURE__*/dual(2, (self, value) => self.offer(value));
/** @internal */
export const offerAll = /*#__PURE__*/dual(2, (self, iterable) => self.offerAll(iterable));
/** @internal */
export const peek = self => self.peek;
/** @internal */
export const peekOption = self => self.peekOption;
/** @internal */
export const poll = self => pipe(self.takeUpTo(1), core.map(RA.head));
/** @internal */
export const seek = /*#__PURE__*/dual(2, (self, predicate) => seekLoop(self, predicate));
const seekLoop = (self, predicate) => core.flatMap(self.take, a => predicate(a) ? core.succeed(a) : seekLoop(self, predicate));
/** @internal */
export const shutdown = self => self.shutdown;
/** @internal */
export const size = self => self.size;
/** @internal */
export const sliding = requestedCapacity => makeQueue(requestedCapacity, Sliding);
/** @internal */
export const take = self => self.take;
/** @internal */
export const takeAll = self => self.takeAll;
/** @internal */
export const takeBetween = /*#__PURE__*/dual(3, (self, min, max) => stm.suspend(() => {
const takeRemainder = (min, max, acc) => {
if (max < min) {
return core.succeed(acc);
}
return pipe(self.takeUpTo(max), core.flatMap(taken => {
const remaining = min - taken.length;
if (remaining === 1) {
return pipe(self.take, core.map(a => pipe(acc, Chunk.appendAll(Chunk.unsafeFromArray(taken)), Chunk.append(a))));
}
if (remaining > 1) {
return pipe(self.take, core.flatMap(a => takeRemainder(remaining - 1, max - taken.length - 1, pipe(acc, Chunk.appendAll(Chunk.unsafeFromArray(taken)), Chunk.append(a)))));
}
return core.succeed(pipe(acc, Chunk.appendAll(Chunk.unsafeFromArray(taken))));
}));
};
return core.map(takeRemainder(min, max, Chunk.empty()), c => Array.from(c));
}));
/** @internal */
export const takeN = /*#__PURE__*/dual(2, (self, n) => pipe(self, takeBetween(n, n)));
/** @internal */
export const takeUpTo = /*#__PURE__*/dual(2, (self, max) => self.takeUpTo(max));
/** @internal */
export const unbounded = () => makeQueue(Number.MAX_SAFE_INTEGER, Dropping);
const makeQueue = (requestedCapacity, strategy) => core.map(tRef.make([]), ref => new TQueueImpl(ref, requestedCapacity, strategy));
//# sourceMappingURL=tQueue.js.map

File diff suppressed because one or more lines are too long

82
node_modules/effect/dist/esm/internal/stm/tRandom.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
import * as Context from "../../Context.js";
import { pipe } from "../../Function.js";
import * as Layer from "../../Layer.js";
import * as Random from "../../Utils.js";
import * as core from "./core.js";
import * as stm from "./stm.js";
import * as tArray from "./tArray.js";
import * as tRef from "./tRef.js";
const TRandomSymbolKey = "effect/TRandom";
/** @internal */
export const TRandomTypeId = /*#__PURE__*/Symbol.for(TRandomSymbolKey);
const randomInteger = state => {
const prng = new Random.PCGRandom();
prng.setState(state);
return [prng.integer(0), prng.getState()];
};
const randomIntegerBetween = (low, high) => {
return state => {
const prng = new Random.PCGRandom();
prng.setState(state);
return [prng.integer(high - low) + low, prng.getState()];
};
};
const randomNumber = state => {
const prng = new Random.PCGRandom();
prng.setState(state);
return [prng.number(), prng.getState()];
};
const withState = (state, f) => {
return pipe(state, tRef.modify(f));
};
const shuffleWith = (iterable, nextIntBounded) => {
const swap = (buffer, index1, index2) => pipe(buffer, tArray.get(index1), core.flatMap(tmp => pipe(buffer, tArray.updateSTM(index1, () => pipe(buffer, tArray.get(index2))), core.zipRight(pipe(buffer, tArray.update(index2, () => tmp))))));
return pipe(tArray.fromIterable(iterable), core.flatMap(buffer => {
const array = [];
for (let i = array.length; i >= 2; i = i - 1) {
array.push(i);
}
return pipe(array, stm.forEach(n => pipe(nextIntBounded(n), core.flatMap(k => swap(buffer, n - 1, k))), {
discard: true
}), core.zipRight(tArray.toArray(buffer)));
}));
};
/** @internal */
export const Tag = /*#__PURE__*/Context.GenericTag("effect/TRandom");
class TRandomImpl {
state;
[TRandomTypeId] = TRandomTypeId;
constructor(state) {
this.state = state;
this.next = withState(this.state, randomNumber);
this.nextBoolean = core.flatMap(this.next, n => core.succeed(n > 0.5));
this.nextInt = withState(this.state, randomInteger);
}
next;
nextBoolean;
nextInt;
nextRange(min, max) {
return core.flatMap(this.next, n => core.succeed((max - min) * n + min));
}
nextIntBetween(low, high) {
return withState(this.state, randomIntegerBetween(low, high));
}
shuffle(elements) {
return shuffleWith(elements, n => this.nextIntBetween(0, n));
}
}
/** @internal */
export const live = /*#__PURE__*/Layer.effect(Tag, /*#__PURE__*/pipe(/*#__PURE__*/tRef.make(/*#__PURE__*/new Random.PCGRandom(Math.random() * 4294967296 >>> 0).getState()), /*#__PURE__*/core.map(seed => new TRandomImpl(seed)), core.commit));
/** @internal */
export const next = /*#__PURE__*/core.flatMap(Tag, random => random.next);
/** @internal */
export const nextBoolean = /*#__PURE__*/core.flatMap(Tag, random => random.nextBoolean);
/** @internal */
export const nextInt = /*#__PURE__*/core.flatMap(Tag, random => random.nextInt);
/** @internal */
export const nextIntBetween = (low, high) => core.flatMap(Tag, random => random.nextIntBetween(low, high));
/** @internal */
export const nextRange = (min, max) => core.flatMap(Tag, random => random.nextRange(min, max));
/** @internal */
export const shuffle = elements => core.flatMap(Tag, random => random.shuffle(elements));
//# sourceMappingURL=tRandom.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,192 @@
import * as Effect from "../../Effect.js";
import * as Equal from "../../Equal.js";
import * as FiberId from "../../FiberId.js";
import { dual } from "../../Function.js";
import * as HashMap from "../../HashMap.js";
import * as Option from "../../Option.js";
import * as core from "./core.js";
import * as tRef from "./tRef.js";
const TReentrantLockSymbolKey = "effect/TReentrantLock";
/** @internal */
export const TReentrantLockTypeId = /*#__PURE__*/Symbol.for(TReentrantLockSymbolKey);
const WriteLockTypeId = /*#__PURE__*/Symbol.for("effect/TReentrantLock/WriteLock");
const ReadLockTypeId = /*#__PURE__*/Symbol.for("effect/TReentrantLock/ReadLock");
class TReentranLockImpl {
state;
[TReentrantLockTypeId] = TReentrantLockTypeId;
constructor(state) {
this.state = state;
}
}
/**
* This data structure describes the state of the lock when multiple fibers
* have acquired read locks. The state is tracked as a map from fiber identity
* to number of read locks acquired by the fiber. This level of detail permits
* upgrading a read lock to a write lock.
*
* @internal
*/
export class ReadLock {
readers;
[ReadLockTypeId] = ReadLockTypeId;
constructor(readers) {
this.readers = readers;
}
get readLocks() {
return Array.from(this.readers).reduce((acc, curr) => acc + curr[1], 0);
}
get writeLocks() {
return 0;
}
readLocksHeld(fiberId) {
return Option.getOrElse(HashMap.get(this.readers, fiberId), () => 0);
}
writeLocksHeld(_fiberId) {
return 0;
}
}
/**
* This data structure describes the state of the lock when a single fiber has
* a write lock. The fiber has an identity, and may also have acquired a
* certain number of read locks.
*
* @internal
*/
export class WriteLock {
readLocks;
writeLocks;
fiberId;
[WriteLockTypeId] = WriteLockTypeId;
constructor(readLocks, writeLocks, fiberId) {
this.readLocks = readLocks;
this.writeLocks = writeLocks;
this.fiberId = fiberId;
}
readLocksHeld(fiberId) {
return Equal.equals(fiberId)(this.fiberId) ? this.readLocks : 0;
}
writeLocksHeld(fiberId) {
return Equal.equals(fiberId)(this.fiberId) ? this.writeLocks : 0;
}
}
const isReadLock = lock => {
return ReadLockTypeId in lock;
};
const isWriteLock = lock => {
return WriteLockTypeId in lock;
};
/**
* An empty read lock state, in which no fiber holds any read locks.
*/
const emptyReadLock = /*#__PURE__*/new ReadLock(/*#__PURE__*/HashMap.empty());
/**
* Creates a new read lock where the specified fiber holds the specified
* number of read locks.
*/
const makeReadLock = (fiberId, count) => {
if (count <= 0) {
return emptyReadLock;
}
return new ReadLock(HashMap.make([fiberId, count]));
};
/**
* Determines if there is no other holder of read locks aside from the
* specified fiber id. If there are no other holders of read locks aside
* from the specified fiber id, then it is safe to upgrade the read lock
* into a write lock.
*/
const noOtherHolder = (readLock, fiberId) => {
return HashMap.isEmpty(readLock.readers) || HashMap.size(readLock.readers) === 1 && HashMap.has(readLock.readers, fiberId);
};
/**
* Adjusts the number of read locks held by the specified fiber id.
*/
const adjustReadLock = (readLock, fiberId, adjustment) => {
const total = readLock.readLocksHeld(fiberId);
const newTotal = total + adjustment;
if (newTotal < 0) {
throw new Error("BUG - TReentrantLock.ReadLock.adjust - please report an issue at https://github.com/Effect-TS/effect/issues");
}
if (newTotal === 0) {
return new ReadLock(HashMap.remove(readLock.readers, fiberId));
}
return new ReadLock(HashMap.set(readLock.readers, fiberId, newTotal));
};
const adjustRead = (self, delta) => core.withSTMRuntime(runtime => {
const lock = tRef.unsafeGet(self.state, runtime.journal);
if (isReadLock(lock)) {
const result = adjustReadLock(lock, runtime.fiberId, delta);
tRef.unsafeSet(self.state, result, runtime.journal);
return core.succeed(result.readLocksHeld(runtime.fiberId));
}
if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) {
const newTotal = lock.readLocks + delta;
if (newTotal < 0) {
throw new Error(`Defect: Fiber ${FiberId.threadName(runtime.fiberId)} releasing read locks it does not hold, newTotal: ${newTotal}`);
}
tRef.unsafeSet(self.state, new WriteLock(newTotal, lock.writeLocks, runtime.fiberId), runtime.journal);
return core.succeed(newTotal);
}
return core.retry;
});
/** @internal */
export const acquireRead = self => adjustRead(self, 1);
/** @internal */
export const acquireWrite = self => core.withSTMRuntime(runtime => {
const lock = tRef.unsafeGet(self.state, runtime.journal);
if (isReadLock(lock) && noOtherHolder(lock, runtime.fiberId)) {
tRef.unsafeSet(self.state, new WriteLock(lock.readLocksHeld(runtime.fiberId), 1, runtime.fiberId), runtime.journal);
return core.succeed(1);
}
if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) {
tRef.unsafeSet(self.state, new WriteLock(lock.readLocks, lock.writeLocks + 1, runtime.fiberId), runtime.journal);
return core.succeed(lock.writeLocks + 1);
}
return core.retry;
});
/** @internal */
export const fiberReadLocks = self => core.effect((journal, fiberId) => tRef.unsafeGet(self.state, journal).readLocksHeld(fiberId));
/** @internal */
export const fiberWriteLocks = self => core.effect((journal, fiberId) => tRef.unsafeGet(self.state, journal).writeLocksHeld(fiberId));
/** @internal */
export const lock = self => writeLock(self);
/** @internal */
export const locked = self => core.zipWith(readLocked(self), writeLocked(self), (x, y) => x || y);
/** @internal */
export const make = /*#__PURE__*/core.map(/*#__PURE__*/tRef.make(emptyReadLock), readLock => new TReentranLockImpl(readLock));
/** @internal */
export const readLock = self => Effect.acquireRelease(core.commit(acquireRead(self)), () => core.commit(releaseRead(self)));
/** @internal */
export const readLocks = self => core.map(tRef.get(self.state), state => state.readLocks);
/** @internal */
export const readLocked = self => core.map(tRef.get(self.state), state => state.readLocks > 0);
/** @internal */
export const releaseRead = self => adjustRead(self, -1);
/** @internal */
export const releaseWrite = self => core.withSTMRuntime(runtime => {
const lock = tRef.unsafeGet(self.state, runtime.journal);
if (isWriteLock(lock) && lock.writeLocks === 1 && Equal.equals(runtime.fiberId)(lock.fiberId)) {
const result = makeReadLock(lock.fiberId, lock.readLocks);
tRef.unsafeSet(self.state, result, runtime.journal);
return core.succeed(result.writeLocksHeld(runtime.fiberId));
}
if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) {
const result = new WriteLock(lock.readLocks, lock.writeLocks - 1, runtime.fiberId);
tRef.unsafeSet(self.state, result, runtime.journal);
return core.succeed(result.writeLocksHeld(runtime.fiberId));
}
throw new Error(`Defect: Fiber ${FiberId.threadName(runtime.fiberId)} releasing write lock it does not hold`);
});
/** @internal */
export const withLock = /*#__PURE__*/dual(2, (effect, self) => withWriteLock(effect, self));
/** @internal */
export const withReadLock = /*#__PURE__*/dual(2, (effect, self) => Effect.uninterruptibleMask(restore => Effect.zipRight(restore(core.commit(acquireRead(self))), Effect.ensuring(effect, core.commit(releaseRead(self))))));
/** @internal */
export const withWriteLock = /*#__PURE__*/dual(2, (effect, self) => Effect.uninterruptibleMask(restore => Effect.zipRight(restore(core.commit(acquireWrite(self))), Effect.ensuring(effect, core.commit(releaseWrite(self))))));
/** @internal */
export const writeLock = self => Effect.acquireRelease(core.commit(acquireWrite(self)), () => core.commit(releaseWrite(self)));
/** @internal */
export const writeLocked = self => core.map(tRef.get(self.state), state => state.writeLocks > 0);
/** @internal */
export const writeLocks = self => core.map(tRef.get(self.state), state => state.writeLocks);
//# sourceMappingURL=tReentrantLock.js.map

File diff suppressed because one or more lines are too long

100
node_modules/effect/dist/esm/internal/stm/tRef.js generated vendored Normal file
View File

@@ -0,0 +1,100 @@
import { dual } from "../../Function.js";
import * as Option from "../../Option.js";
import { pipeArguments } from "../../Pipeable.js";
import * as core from "./core.js";
import * as Entry from "./entry.js";
import * as Versioned from "./versioned.js";
/** @internal */
const TRefSymbolKey = "effect/TRef";
/** @internal */
export const TRefTypeId = /*#__PURE__*/Symbol.for(TRefSymbolKey);
export const tRefVariance = {
/* c8 ignore next */
_A: _ => _
};
/** @internal */
export class TRefImpl {
[TRefTypeId] = tRefVariance;
/** @internal */
todos;
/** @internal */
versioned;
constructor(value) {
this.versioned = new Versioned.Versioned(value);
this.todos = new Map();
}
modify(f) {
return core.effect(journal => {
const entry = getOrMakeEntry(this, journal);
const [retValue, newValue] = f(Entry.unsafeGet(entry));
Entry.unsafeSet(entry, newValue);
return retValue;
});
}
pipe() {
return pipeArguments(this, arguments);
}
}
/** @internal */
export const make = value => core.effect(journal => {
const ref = new TRefImpl(value);
journal.set(ref, Entry.make(ref, true));
return ref;
});
/** @internal */
export const get = self => self.modify(a => [a, a]);
/** @internal */
export const set = /*#__PURE__*/dual(2, (self, value) => self.modify(() => [void 0, value]));
/** @internal */
export const getAndSet = /*#__PURE__*/dual(2, (self, value) => self.modify(a => [a, value]));
/** @internal */
export const getAndUpdate = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [a, f(a)]));
/** @internal */
export const getAndUpdateSome = /*#__PURE__*/dual(2, (self, f) => self.modify(a => Option.match(f(a), {
onNone: () => [a, a],
onSome: b => [a, b]
})));
/** @internal */
export const setAndGet = /*#__PURE__*/dual(2, (self, value) => self.modify(() => [value, value]));
/** @internal */
export const modify = /*#__PURE__*/dual(2, (self, f) => self.modify(f));
/** @internal */
export const modifySome = /*#__PURE__*/dual(3, (self, fallback, f) => self.modify(a => Option.match(f(a), {
onNone: () => [fallback, a],
onSome: b => b
})));
/** @internal */
export const update = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [void 0, f(a)]));
/** @internal */
export const updateAndGet = /*#__PURE__*/dual(2, (self, f) => self.modify(a => {
const b = f(a);
return [b, b];
}));
/** @internal */
export const updateSome = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [void 0, Option.match(f(a), {
onNone: () => a,
onSome: b => b
})]));
/** @internal */
export const updateSomeAndGet = /*#__PURE__*/dual(2, (self, f) => self.modify(a => Option.match(f(a), {
onNone: () => [a, a],
onSome: b => [b, b]
})));
/** @internal */
const getOrMakeEntry = (self, journal) => {
if (journal.has(self)) {
return journal.get(self);
}
const entry = Entry.make(self, false);
journal.set(self, entry);
return entry;
};
/** @internal */
export const unsafeGet = /*#__PURE__*/dual(2, (self, journal) => Entry.unsafeGet(getOrMakeEntry(self, journal)));
/** @internal */
export const unsafeSet = /*#__PURE__*/dual(3, (self, value, journal) => {
const entry = getOrMakeEntry(self, journal);
Entry.unsafeSet(entry, value);
return undefined;
});
//# sourceMappingURL=tRef.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
import * as Cause from "../../Cause.js";
import * as Effect from "../../Effect.js";
import { dual } from "../../Function.js";
import * as STM from "../../STM.js";
import * as core from "./core.js";
import * as tRef from "./tRef.js";
/** @internal */
const TSemaphoreSymbolKey = "effect/TSemaphore";
/** @internal */
export const TSemaphoreTypeId = /*#__PURE__*/Symbol.for(TSemaphoreSymbolKey);
/** @internal */
class TSemaphoreImpl {
permits;
[TSemaphoreTypeId] = TSemaphoreTypeId;
constructor(permits) {
this.permits = permits;
}
}
/** @internal */
export const make = permits => STM.map(tRef.make(permits), permits => new TSemaphoreImpl(permits));
/** @internal */
export const acquire = self => acquireN(self, 1);
/** @internal */
export const acquireN = /*#__PURE__*/dual(2, (self, n) => core.withSTMRuntime(driver => {
if (n < 0) {
throw new Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.acquireN`);
}
const value = tRef.unsafeGet(self.permits, driver.journal);
if (value < n) {
return STM.retry;
} else {
return STM.succeed(tRef.unsafeSet(self.permits, value - n, driver.journal));
}
}));
/** @internal */
export const available = self => tRef.get(self.permits);
/** @internal */
export const release = self => releaseN(self, 1);
/** @internal */
export const releaseN = /*#__PURE__*/dual(2, (self, n) => core.withSTMRuntime(driver => {
if (n < 0) {
throw new Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.releaseN`);
}
const current = tRef.unsafeGet(self.permits, driver.journal);
return STM.succeed(tRef.unsafeSet(self.permits, current + n, driver.journal));
}));
/** @internal */
export const withPermit = /*#__PURE__*/dual(2, (self, semaphore) => withPermits(self, semaphore, 1));
/** @internal */
export const withPermits = /*#__PURE__*/dual(3, (self, semaphore, permits) => Effect.uninterruptibleMask(restore => Effect.zipRight(restore(core.commit(acquireN(permits)(semaphore))), Effect.ensuring(self, core.commit(releaseN(permits)(semaphore))))));
/** @internal */
export const withPermitScoped = self => withPermitsScoped(self, 1);
/** @internal */
export const withPermitsScoped = /*#__PURE__*/dual(2, (self, permits) => Effect.acquireReleaseInterruptible(core.commit(acquireN(self, permits)), () => core.commit(releaseN(self, permits))));
/** @internal */
export const unsafeMakeSemaphore = permits => {
return new TSemaphoreImpl(new tRef.TRefImpl(permits));
};
//# sourceMappingURL=tSemaphore.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tSemaphore.js","names":["Cause","Effect","dual","STM","core","tRef","TSemaphoreSymbolKey","TSemaphoreTypeId","Symbol","for","TSemaphoreImpl","permits","constructor","make","map","acquire","self","acquireN","n","withSTMRuntime","driver","IllegalArgumentException","value","unsafeGet","journal","retry","succeed","unsafeSet","available","get","release","releaseN","current","withPermit","semaphore","withPermits","uninterruptibleMask","restore","zipRight","commit","ensuring","withPermitScoped","withPermitsScoped","acquireReleaseInterruptible","unsafeMakeSemaphore","TRefImpl"],"sources":["../../../../src/internal/stm/tSemaphore.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,gBAAgB;AACvC,OAAO,KAAKC,MAAM,MAAM,iBAAiB;AACzC,SAASC,IAAI,QAAQ,mBAAmB;AAExC,OAAO,KAAKC,GAAG,MAAM,cAAc;AAGnC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAO,KAAKC,IAAI,MAAM,WAAW;AAEjC;AACA,MAAMC,mBAAmB,GAAG,mBAAmB;AAE/C;AACA,OAAO,MAAMC,gBAAgB,gBAAgCC,MAAM,CAACC,GAAG,CACrEH,mBAAmB,CACW;AAEhC;AACA,MAAMI,cAAc;EAEGC,OAAA;EADZ,CAACJ,gBAAgB,IAAiCA,gBAAgB;EAC3EK,YAAqBD,OAA0B;IAA1B,KAAAA,OAAO,GAAPA,OAAO;EAAsB;;AAGpD;AACA,OAAO,MAAME,IAAI,GAAIF,OAAe,IAClCR,GAAG,CAACW,GAAG,CAACT,IAAI,CAACQ,IAAI,CAACF,OAAO,CAAC,EAAGA,OAAO,IAAK,IAAID,cAAc,CAACC,OAAO,CAAC,CAAC;AAEvE;AACA,OAAO,MAAMI,OAAO,GAAIC,IAA2B,IAAoBC,QAAQ,CAACD,IAAI,EAAE,CAAC,CAAC;AAExF;AACA,OAAO,MAAMC,QAAQ,gBAAGf,IAAI,CAG1B,CAAC,EAAE,CAACc,IAAI,EAAEE,CAAC,KACXd,IAAI,CAACe,cAAc,CAAEC,MAAM,IAAI;EAC7B,IAAIF,CAAC,GAAG,CAAC,EAAE;IACT,MAAM,IAAIlB,KAAK,CAACqB,wBAAwB,CAAC,6BAA6BH,CAAC,+BAA+B,CAAC;EACzG;EACA,MAAMI,KAAK,GAAG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D;AACA,OAAO,MAAMC,WAAW,gBAAGjC,IAAI,CAU7B,CAAC,EAAE,CAACc,IAAI,EAAEkB,SAAS,EAAEvB,OAAO,KAC5BV,MAAM,CAACmC,mBAAmB,CAAEC,OAAO,IACjCpC,MAAM,CAACqC,QAAQ,CACbD,OAAO,CAACjC,IAAI,CAACmC,MAAM,CAACtB,QAAQ,CAACN,OAAO,CAAC,CAACuB,SAAS,CAAC,CAAC,CAAC,EAClDjC,MAAM,CAACuC,QAAQ,CACbxB,IAAI,EACJZ,IAAI,CAACmC,MAAM,CAACR,QAAQ,CAACpB,OAAO,CAAC,CAACuB,SAAS,CAAC,CAAC,CAC1C,CACF,CACF,CAAC;AAEJ;AACA,OAAO,MAAMO,gBAAgB,GAAIzB,IAA2B,IAC1D0B,iBAAiB,CAAC1B,IAAI,EAAE,CAAC,CAAC;AAE5B;AACA,OAAO,MAAM0B,iBAAiB,gBAAGxC,IAAI,CAGnC,CAAC,EAAE,CAACc,IAAI,EAAEL,OAAO,KACjBV,MAAM,CAAC0C,2BAA2B,CAChCvC,IAAI,CAACmC,MAAM,CAACtB,QAAQ,CAACD,IAAI,EAAEL,OAAO,CAAC,CAAC,EACpC,MAAMP,IAAI,CAACmC,MAAM,CAACR,QAAQ,CAACf,IAAI,EAAEL,OAAO,CAAC,CAAC,CAC3C,CAAC;AAEJ;AACA,OAAO,MAAMiC,mBAAmB,GAAIjC,OAAe,IAA2B;EAC5E,OAAO,IAAID,cAAc,CAAC,IAAIL,IAAI,CAACwC,QAAQ,CAAClC,OAAO,CAAC,CAAC;AACvD,CAAC","ignoreList":[]}

88
node_modules/effect/dist/esm/internal/stm/tSet.js generated vendored Normal file
View File

@@ -0,0 +1,88 @@
import * as RA from "../../Array.js";
import * as Chunk from "../../Chunk.js";
import { dual, pipe } from "../../Function.js";
import * as HashSet from "../../HashSet.js";
import { hasProperty } from "../../Predicate.js";
import * as STM from "../../STM.js";
import * as core from "./core.js";
import * as tMap from "./tMap.js";
/** @internal */
const TSetSymbolKey = "effect/TSet";
/** @internal */
export const TSetTypeId = /*#__PURE__*/Symbol.for(TSetSymbolKey);
const tSetVariance = {
/* c8 ignore next */
_A: _ => _
};
/** @internal */
class TSetImpl {
tMap;
[TSetTypeId] = tSetVariance;
constructor(tMap) {
this.tMap = tMap;
}
}
const isTSet = u => hasProperty(u, TSetTypeId);
/** @internal */
export const add = /*#__PURE__*/dual(2, (self, value) => tMap.set(self.tMap, value, void 0));
/** @internal */
export const difference = /*#__PURE__*/dual(2, (self, other) => core.flatMap(toHashSet(other), values => removeIf(self, value => HashSet.has(values, value), {
discard: true
})));
/** @internal */
export const empty = () => fromIterable([]);
/** @internal */
export const forEach = /*#__PURE__*/dual(2, (self, f) => reduceSTM(self, void 0, (_, value) => f(value)));
/** @internal */
export const fromIterable = iterable => core.map(tMap.fromIterable(Array.from(iterable).map(a => [a, void 0])), tMap => new TSetImpl(tMap));
/** @internal */
export const has = /*#__PURE__*/dual(2, (self, value) => tMap.has(self.tMap, value));
/** @internal */
export const intersection = /*#__PURE__*/dual(2, (self, other) => core.flatMap(toHashSet(other), values => pipe(self, retainIf(value => pipe(values, HashSet.has(value)), {
discard: true
}))));
/** @internal */
export const isEmpty = self => tMap.isEmpty(self.tMap);
/** @internal */
export const make = (...elements) => fromIterable(elements);
/** @internal */
export const reduce = /*#__PURE__*/dual(3, (self, zero, f) => tMap.reduce(self.tMap, zero, (acc, _, key) => f(acc, key)));
/** @internal */
export const reduceSTM = /*#__PURE__*/dual(3, (self, zero, f) => tMap.reduceSTM(self.tMap, zero, (acc, _, key) => f(acc, key)));
/** @internal */
export const remove = /*#__PURE__*/dual(2, (self, value) => tMap.remove(self.tMap, value));
/** @internal */
export const removeAll = /*#__PURE__*/dual(2, (self, iterable) => tMap.removeAll(self.tMap, iterable));
/** @internal */
export const removeIf = /*#__PURE__*/dual(args => isTSet(args[0]), (self, predicate, options) => options?.discard === true ? tMap.removeIf(self.tMap, key => predicate(key), {
discard: true
}) : pipe(tMap.removeIf(self.tMap, key => predicate(key)), core.map(RA.map(entry => entry[0]))));
/** @internal */
export const retainIf = /*#__PURE__*/dual(args => isTSet(args[0]), (self, predicate, options) => options?.discard === true ? tMap.retainIf(self.tMap, key => predicate(key), {
discard: true
}) : pipe(tMap.retainIf(self.tMap, key => predicate(key)), core.map(RA.map(entry => entry[0]))));
/** @internal */
export const size = self => core.map(toChunk(self), chunk => chunk.length);
/** @internal */
export const takeFirst = /*#__PURE__*/dual(2, (self, pf) => tMap.takeFirst(self.tMap, key => pf(key)));
/** @internal */
export const takeFirstSTM = /*#__PURE__*/dual(2, (self, pf) => tMap.takeFirstSTM(self.tMap, key => pf(key)));
/** @internal */
export const takeSome = /*#__PURE__*/dual(2, (self, pf) => tMap.takeSome(self.tMap, key => pf(key)));
/** @internal */
export const takeSomeSTM = /*#__PURE__*/dual(2, (self, pf) => tMap.takeSomeSTM(self.tMap, key => pf(key)));
/** @internal */
export const toChunk = self => tMap.keys(self.tMap).pipe(STM.map(Chunk.unsafeFromArray));
/** @internal */
export const toHashSet = self => reduce(self, HashSet.empty(), (acc, value) => pipe(acc, HashSet.add(value)));
/** @internal */
export const toArray = self => reduce(self, [], (acc, value) => [...acc, value]);
/** @internal */
export const toReadonlySet = self => core.map(toArray(self), values => new Set(values));
/** @internal */
export const transform = /*#__PURE__*/dual(2, (self, f) => tMap.transform(self.tMap, (key, value) => [f(key), value]));
/** @internal */
export const transformSTM = /*#__PURE__*/dual(2, (self, f) => tMap.transformSTM(self.tMap, (key, value) => core.map(f(key), a => [a, value])));
/** @internal */
export const union = /*#__PURE__*/dual(2, (self, other) => forEach(other, value => add(self, value)));
//# sourceMappingURL=tSet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,166 @@
import * as Effect from "../../Effect.js";
import { dual, pipe } from "../../Function.js";
import * as Option from "../../Option.js";
import { pipeArguments } from "../../Pipeable.js";
import * as STM from "../../STM.js";
import * as TPubSub from "../../TPubSub.js";
import * as TQueue from "../../TQueue.js";
import * as TRef from "../../TRef.js";
import * as stream from "../stream.js";
import { tDequeueVariance } from "./tQueue.js";
import { tRefVariance } from "./tRef.js";
/** @internal */
const TSubscriptionRefSymbolKey = "effect/TSubscriptionRef";
/** @internal */
export const TSubscriptionRefTypeId = /*#__PURE__*/Symbol.for(TSubscriptionRefSymbolKey);
const TSubscriptionRefVariance = {
/* c8 ignore next */
_A: _ => _
};
class TDequeueMerge {
first;
second;
[TQueue.TDequeueTypeId] = tDequeueVariance;
constructor(first, second) {
this.first = first;
this.second = second;
}
peek = /*#__PURE__*/STM.gen(this, function* () {
const first = yield* this.peekOption;
if (first._tag === "Some") {
return first.value;
}
return yield* STM.retry;
});
peekOption = /*#__PURE__*/STM.gen(this, function* () {
const first = yield* this.first.peekOption;
if (first._tag === "Some") {
return first;
}
const second = yield* this.second.peekOption;
if (second._tag === "Some") {
return second;
}
return Option.none();
});
take = /*#__PURE__*/STM.gen(this, function* () {
if (!(yield* this.first.isEmpty)) {
return yield* this.first.take;
}
if (!(yield* this.second.isEmpty)) {
return yield* this.second.take;
}
return yield* STM.retry;
});
takeAll = /*#__PURE__*/STM.gen(this, function* () {
return [...(yield* this.first.takeAll), ...(yield* this.second.takeAll)];
});
takeUpTo(max) {
return STM.gen(this, function* () {
const first = yield* this.first.takeUpTo(max);
if (first.length >= max) {
return first;
}
return [...first, ...(yield* this.second.takeUpTo(max - first.length))];
});
}
capacity() {
return this.first.capacity() + this.second.capacity();
}
size = /*#__PURE__*/STM.gen(this, function* () {
return (yield* this.first.size) + (yield* this.second.size);
});
isFull = /*#__PURE__*/STM.gen(this, function* () {
return (yield* this.first.isFull) && (yield* this.second.isFull);
});
isEmpty = /*#__PURE__*/STM.gen(this, function* () {
return (yield* this.first.isEmpty) && (yield* this.second.isEmpty);
});
shutdown = /*#__PURE__*/STM.gen(this, function* () {
yield* this.first.shutdown;
yield* this.second.shutdown;
});
isShutdown = /*#__PURE__*/STM.gen(this, function* () {
return (yield* this.first.isShutdown) && (yield* this.second.isShutdown);
});
awaitShutdown = /*#__PURE__*/STM.gen(this, function* () {
yield* this.first.awaitShutdown;
yield* this.second.awaitShutdown;
});
}
/** @internal */
class TSubscriptionRefImpl {
ref;
pubsub;
[TSubscriptionRefTypeId] = TSubscriptionRefVariance;
[TRef.TRefTypeId] = tRefVariance;
constructor(ref, pubsub) {
this.ref = ref;
this.pubsub = pubsub;
}
get todos() {
return this.ref.todos;
}
get versioned() {
return this.ref.versioned;
}
pipe() {
return pipeArguments(this, arguments);
}
get changes() {
return STM.gen(this, function* () {
const first = yield* TQueue.unbounded();
yield* TQueue.offer(first, yield* TRef.get(this.ref));
return new TDequeueMerge(first, yield* TPubSub.subscribe(this.pubsub));
});
}
modify(f) {
return pipe(TRef.get(this.ref), STM.map(f), STM.flatMap(([b, a]) => pipe(TRef.set(this.ref, a), STM.as(b), STM.zipLeft(TPubSub.publish(this.pubsub, a)))));
}
}
/** @internal */
export const make = value => pipe(STM.all([TPubSub.unbounded(), TRef.make(value)]), STM.map(([pubsub, ref]) => new TSubscriptionRefImpl(ref, pubsub)));
/** @internal */
export const get = self => TRef.get(self.ref);
/** @internal */
export const set = /*#__PURE__*/dual(2, (self, value) => self.modify(() => [void 0, value]));
/** @internal */
export const getAndSet = /*#__PURE__*/dual(2, (self, value) => self.modify(a => [a, value]));
/** @internal */
export const getAndUpdate = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [a, f(a)]));
/** @internal */
export const getAndUpdateSome = /*#__PURE__*/dual(2, (self, f) => self.modify(a => Option.match(f(a), {
onNone: () => [a, a],
onSome: b => [a, b]
})));
/** @internal */
export const setAndGet = /*#__PURE__*/dual(2, (self, value) => self.modify(() => [value, value]));
/** @internal */
export const modify = /*#__PURE__*/dual(2, (self, f) => self.modify(f));
/** @internal */
export const modifySome = /*#__PURE__*/dual(3, (self, fallback, f) => self.modify(a => Option.match(f(a), {
onNone: () => [fallback, a],
onSome: b => b
})));
/** @internal */
export const update = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [void 0, f(a)]));
/** @internal */
export const updateAndGet = /*#__PURE__*/dual(2, (self, f) => self.modify(a => {
const b = f(a);
return [b, b];
}));
/** @internal */
export const updateSome = /*#__PURE__*/dual(2, (self, f) => self.modify(a => [void 0, Option.match(f(a), {
onNone: () => a,
onSome: b => b
})]));
/** @internal */
export const updateSomeAndGet = /*#__PURE__*/dual(2, (self, f) => self.modify(a => Option.match(f(a), {
onNone: () => [a, a],
onSome: b => [b, b]
})));
/** @internal */
export const changesScoped = self => Effect.acquireRelease(self.changes, TQueue.shutdown);
/** @internal */
export const changesStream = self => stream.unwrap(Effect.map(self.changes, stream.fromTQueue));
//# sourceMappingURL=tSubscriptionRef.js.map

File diff suppressed because one or more lines are too long

16
node_modules/effect/dist/esm/internal/stm/tryCommit.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import * as OpCodes from "./opCodes/tryCommit.js";
/** @internal */
export const done = exit => {
return {
_tag: OpCodes.OP_DONE,
exit
};
};
/** @internal */
export const suspend = journal => {
return {
_tag: OpCodes.OP_SUSPEND,
journal
};
};
//# sourceMappingURL=tryCommit.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tryCommit.js","names":["OpCodes","done","exit","_tag","OP_DONE","suspend","journal","OP_SUSPEND"],"sources":["../../../../src/internal/stm/tryCommit.ts"],"sourcesContent":[null],"mappings":"AAEA,OAAO,KAAKA,OAAO,MAAM,wBAAwB;AAiBjD;AACA,OAAO,MAAMC,IAAI,GAAUC,IAAqB,IAAqB;EACnE,OAAO;IACLC,IAAI,EAAEH,OAAO,CAACI,OAAO;IACrBF;GACD;AACH,CAAC;AAED;AACA,OAAO,MAAMG,OAAO,GAAIC,OAAwB,IAAsB;EACpE,OAAO;IACLH,IAAI,EAAEH,OAAO,CAACO,UAAU;IACxBD;GACD;AACH,CAAC","ignoreList":[]}

11
node_modules/effect/dist/esm/internal/stm/txnId.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/** @internal */
const txnCounter = {
ref: 0
};
/** @internal */
export const make = () => {
const newId = txnCounter.ref + 1;
txnCounter.ref = newId;
return newId;
};
//# sourceMappingURL=txnId.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"txnId.js","names":["txnCounter","ref","make","newId"],"sources":["../../../../src/internal/stm/txnId.ts"],"sourcesContent":[null],"mappings":"AAKA;AACA,MAAMA,UAAU,GAAG;EAAEC,GAAG,EAAE;AAAC,CAAE;AAE7B;AACA,OAAO,MAAMC,IAAI,GAAGA,CAAA,KAAY;EAC9B,MAAMC,KAAK,GAAGH,UAAU,CAACC,GAAG,GAAG,CAAC;EAChCD,UAAU,CAACC,GAAG,GAAGE,KAAK;EACtB,OAAOA,KAAc;AACvB,CAAC","ignoreList":[]}

View File

@@ -0,0 +1,8 @@
/** @internal */
export class Versioned {
value;
constructor(value) {
this.value = value;
}
}
//# sourceMappingURL=versioned.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"versioned.js","names":["Versioned","value","constructor"],"sources":["../../../../src/internal/stm/versioned.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,OAAM,MAAOA,SAAS;EACCC,KAAA;EAArBC,YAAqBD,KAAQ;IAAR,KAAAA,KAAK,GAALA,KAAK;EAAM","ignoreList":[]}