Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

@actor-system/core

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@actor-system/core - npm Package Compare versions

Comparing version
0.2.0
to
0.2.1
+3
-9
dist/actor/actor-system.d.ts
import { Path } from '../__bundle__/shared/dist/path.js';
import { Behavior } from '../behavior.js';
import { SystemConfig, Profile, Props } from '../configs.js';
import { RequiredSystemConfig, SystemConfig, Props } from '../configs.js';
import { ActorRef, SystemLookup } from './actor-ref.js';

@@ -9,6 +9,4 @@

readonly name: string;
readonly config: Required<SystemConfig> & {
defaultProfile: Required<Profile>;
};
readonly path: Path.System;
readonly config: RequiredSystemConfig;
readonly deadLetters: ActorRef<unknown>;

@@ -19,7 +17,3 @@ /**

*/
static create<U = never>({ behavior, name, config, }: {
behavior: Behavior<U>;
name: string;
config?: SystemConfig;
}): ActorSystem<U>;
static create<U = never>(behavior: Behavior<U>, name: string, config?: SystemConfig): ActorSystem<U>;
private constructor();

@@ -26,0 +20,0 @@ get whenTerminated(): Promise<void>;

import { Path } from '../__bundle__/shared/dist/path.internal.js';
import { Behavior } from '../behavior.internal.js';
import { SystemConfig, Profile, Props } from '../configs.internal.js';
import { RequiredSystemConfig, SystemConfig, Props } from '../configs.internal.js';
import { Dispatcher } from '../dispatcher.internal.js';
import { ActorRef, SystemLookup } from './actor-ref.internal.js';
import { $systemLookup } from '../strings.internal.js';
import { Scheduler } from '../__bundle__/scheduler/dist/types.internal.js';

@@ -11,6 +12,4 @@ declare class ActorSystem<T = unknown> implements ActorRef<T>, SystemLookup {

readonly name: string;
readonly config: Required<SystemConfig> & {
defaultProfile: Required<Profile>;
};
readonly path: Path.System;
readonly config: RequiredSystemConfig;
readonly deadLetters: ActorRef<unknown>;

@@ -25,7 +24,3 @@ /** @internal */

*/
static create<U = never>({ behavior, name, config, }: {
behavior: Behavior<U>;
name: string;
config?: SystemConfig;
}): ActorSystem<U>;
static create<U = never>(behavior: Behavior<U>, name: string, config?: SystemConfig): ActorSystem<U>;
private constructor();

@@ -42,3 +37,3 @@ get whenTerminated(): Promise<void>;

/** @internal */
_getOrCreateDispatcher(profile?: Profile): Dispatcher;
_getOrCreateDispatcher(scheduler: Scheduler): Dispatcher;
/** @internal */

@@ -45,0 +40,0 @@ _addActorRefToRegistry<U>(ref: ActorRef<U>): void;

import { createPath, resolvePath } from '../__bundle__/shared/dist/path.js';
import { _empty } from '../behavior.js';
import { defaultConfig, defaultProfile } from '../config.js';
import { sysConfigWithDefaults } from '../config.js';
import { Dispatcher } from '../dispatcher.js';

@@ -13,4 +13,4 @@ import { Actor } from './actor.js';

name;
path;
config;
path;
deadLetters;

@@ -24,3 +24,3 @@ /** @internal */

#actorRefsRegistry = new Map();
#dispatcherByProfile = new Map();
#dispatcherByScheduler = new Map();
#whenTerminated = Promise.withResolvers();

@@ -31,3 +31,3 @@ /**

*/
static create({ behavior, name, config, }) {
static create(behavior, name, config) {
return new ActorSystem(behavior, name, config);

@@ -37,10 +37,3 @@ }

this.name = name;
this.config = {
...defaultConfig,
...partialConfig,
defaultProfile: {
...defaultConfig.defaultProfile,
...partialConfig?.defaultProfile,
},
};
this.config = sysConfigWithDefaults(partialConfig);
this.path = createPath({ ...this.config, system: name });

@@ -97,12 +90,8 @@ // Register the root actor (system) in the registry

/** @internal */
_getOrCreateDispatcher(profile = defaultProfile) {
const existing = this.#dispatcherByProfile.get(profile);
_getOrCreateDispatcher(scheduler) {
const existing = this.#dispatcherByScheduler.get(scheduler);
if (existing)
return existing;
const { lane = defaultProfile.lane, budget = defaultProfile.budget } = profile;
const dispatcher = Dispatcher.create({
budget,
scheduler: lane,
});
this.#dispatcherByProfile.set(profile, dispatcher);
const dispatcher = Dispatcher.create({ scheduler });
this.#dispatcherByScheduler.set(scheduler, dispatcher);
return dispatcher;

@@ -109,0 +98,0 @@ }

@@ -28,2 +28,3 @@ import { Path } from '../__bundle__/shared/dist/path.internal.js';

readonly spawn: <U>(behavior: Behavior<U>, name?: string, props?: Props) => ActorRef<U>;
readonly pipeToSelf: (promise: Promise<T>) => void;
static create<U>({ path, parent, system, behavior, props, }: {

@@ -30,0 +31,0 @@ path: Path.Actor;

@@ -12,2 +12,3 @@ import { mutable } from '../__bundle__/shared/dist/index.js';

import { ChildManager, InvalidActorNameError } from './child-manager.js';
import { budgetWithDefaults } from '../config.js';
import { generateMonotonicULID } from '../__bundle__/shared/dist/monotonicULID.js';

@@ -34,2 +35,3 @@ import { resolvePath } from '../__bundle__/shared/dist/path.js';

spawn = this.#spawn.bind(this);
pipeToSelf = this.#pipeToSelf.bind(this);
#initialBehavior;

@@ -42,3 +44,4 @@ #childManager = new ChildManager();

const profile = { ...system.config.defaultProfile, ...props?.profile };
const dispatcher = system._getOrCreateDispatcher(profile);
const budget = budgetWithDefaults(props?.profile?.budget);
const dispatcher = system._getOrCreateDispatcher(profile.lane);
const ref = LocalActorRef.create(path, system);

@@ -48,2 +51,3 @@ const actor = new Actor(path, behavior, parent?.self ?? system, system, dispatcher);

const mailbox = Mailbox.create({
budget,
dispatcher,

@@ -185,2 +189,7 @@ receiver: actor,

}
#pipeToSelf(promise) {
promise
.then((value) => this.self.tell(value))
.catch((error) => this.self.tell(error));
}
#restartActor(checkpointBehavior) {

@@ -187,0 +196,0 @@ this.#receiveDomainMessageOrSignal(postStop);

@@ -51,4 +51,25 @@ import { Behavior } from '../behavior.js';

delegate(delegator: Behavior<T>, message: T | Signal): Behavior<T>;
/**
* Pipe the result of a Promise back to this actor.
* When the promise resolves, the value is sent to self.
* When the promise rejects, the error is sent to self.
*
* @param promise - The promise to pipe to self
*
* @example
* ```typescript
* // Simple case - pipe result directly
* context.pipeToSelf(ask(otherActor, request));
*
* // With transformation
* context.pipeToSelf(
* ask(otherActor, request)
* .then(res => new SuccessMessage(res))
* .catch(err => new ErrorMessage(err))
* );
* ```
*/
pipeToSelf(promise: Promise<T>): void;
}
export type { ActorContext };

@@ -51,4 +51,25 @@ import { Behavior } from '../behavior.internal.js';

delegate(delegator: Behavior<T>, message: T | Signal): Behavior<T>;
/**
* Pipe the result of a Promise back to this actor.
* When the promise resolves, the value is sent to self.
* When the promise rejects, the error is sent to self.
*
* @param promise - The promise to pipe to self
*
* @example
* ```typescript
* // Simple case - pipe result directly
* context.pipeToSelf(ask(otherActor, request));
*
* // With transformation
* context.pipeToSelf(
* ask(otherActor, request)
* .then(res => new SuccessMessage(res))
* .catch(err => new ErrorMessage(err))
* );
* ```
*/
pipeToSelf(promise: Promise<T>): void;
}
export type { ActorContext };

@@ -16,3 +16,19 @@ import { task } from '@actor-system/scheduler';

};
const sysConfigWithDefaults = (partialConfig) => ({
...defaultConfig,
...partialConfig,
defaultProfile: {
...defaultConfig.defaultProfile,
...partialConfig?.defaultProfile,
budget: {
...defaultConfig.defaultProfile.budget,
...partialConfig?.defaultProfile?.budget,
},
},
});
const budgetWithDefaults = (partialBudget) => ({
...defaultProfile.budget,
...partialBudget,
});
export { defaultConfig, defaultProfile };
export { budgetWithDefaults, defaultConfig, defaultProfile, sysConfigWithDefaults };

@@ -36,2 +36,7 @@ import { Scheduler } from '@actor-system/scheduler';

}
interface RequiredProfile {
readonly lane: Lane;
readonly budget: Required<Budget>;
readonly mailboxType: MailboxType;
}
/**

@@ -47,2 +52,5 @@ * System defaults: a single default Profile (recommended) and optional registry.

}
interface RequiredSystemConfig extends Required<SystemConfig> {
readonly defaultProfile: RequiredProfile;
}
/**

@@ -56,2 +64,2 @@ * ActorProps: how a user opts into a Profile, with optional fine-tuning.

export type { Budget, Lane, Profile, Props, SystemConfig };
export type { Budget, Lane, Profile, Props, RequiredProfile, RequiredSystemConfig, SystemConfig };

@@ -36,2 +36,7 @@ import { Scheduler } from './__bundle__/scheduler/dist/types.internal.js';

}
interface RequiredProfile {
readonly lane: Lane;
readonly budget: Required<Budget>;
readonly mailboxType: MailboxType;
}
/**

@@ -47,2 +52,5 @@ * System defaults: a single default Profile (recommended) and optional registry.

}
interface RequiredSystemConfig extends Required<SystemConfig> {
readonly defaultProfile: RequiredProfile;
}
/**

@@ -56,2 +64,2 @@ * ActorProps: how a user opts into a Profile, with optional fine-tuning.

export type { Budget, Lane, Profile, Props, SystemConfig };
export type { Budget, Lane, Profile, Props, RequiredProfile, RequiredSystemConfig, SystemConfig };
import { Scheduler } from '@actor-system/scheduler';
import { SystemMessage } from './system-message.js';
import { Mailbox } from './mailbox/mailbox.js';
import { Budget } from './configs.js';
interface DispatcherConfig {
readonly scheduler: Scheduler;
readonly budget: Budget;
}

@@ -16,4 +14,3 @@ /**

readonly scheduler: Scheduler;
readonly budget: Required<Budget>;
constructor({ scheduler, budget }: DispatcherConfig);
constructor({ scheduler }: DispatcherConfig);
static create(config: DispatcherConfig): Dispatcher;

@@ -20,0 +17,0 @@ dispatch<T>(mailbox: Mailbox<T>, message: T): void;

import { Scheduler } from './__bundle__/scheduler/dist/types.internal.js';
import { SystemMessage } from './system-message.internal.js';
import { Mailbox } from './mailbox/mailbox.internal.js';
import { Budget } from './configs.internal.js';
interface DispatcherConfig {
readonly scheduler: Scheduler;
readonly budget: Budget;
}

@@ -16,4 +14,3 @@ /**

readonly scheduler: Scheduler;
readonly budget: Required<Budget>;
constructor({ scheduler, budget }: DispatcherConfig);
constructor({ scheduler }: DispatcherConfig);
static create(config: DispatcherConfig): Dispatcher;

@@ -20,0 +17,0 @@ dispatch<T>(mailbox: Mailbox<T>, message: T): void;

@@ -1,3 +0,1 @@

import { defaultProfile } from './config.js';
/**

@@ -9,6 +7,4 @@ * Dispatcher is responsible for processing messages from a mailbox.

scheduler;
budget;
constructor({ scheduler, budget }) {
constructor({ scheduler }) {
this.scheduler = scheduler;
this.budget = { ...defaultProfile.budget, ...budget };
}

@@ -15,0 +11,0 @@ static create(config) {

@@ -6,2 +6,3 @@ import { Run } from '@actor-system/scheduler';

import { MessageQueue } from './message-queue.js';
import { Budget } from '../configs.js';

@@ -24,3 +25,4 @@ /**

#private;
static create<T>({ messageQueue, receiver, dispatcher, deadLetters, }: {
readonly budget: Required<Budget>;
static create<T>({ messageQueue, receiver, dispatcher, deadLetters, budget, }: {
messageQueue: MessageQueue<T>;

@@ -30,2 +32,3 @@ receiver: MessageReceiver<T>;

deadLetters?: ActorRef;
budget: Required<Budget>;
}): Mailbox<T>;

@@ -32,0 +35,0 @@ private constructor();

@@ -6,2 +6,3 @@ import { Run } from '../__bundle__/scheduler/dist/types.internal.js';

import { MessageQueue } from './message-queue.internal.js';
import { Budget } from '../configs.internal.js';

@@ -24,3 +25,4 @@ /**

#private;
static create<T>({ messageQueue, receiver, dispatcher, deadLetters, }: {
readonly budget: Required<Budget>;
static create<T>({ messageQueue, receiver, dispatcher, deadLetters, budget, }: {
messageQueue: MessageQueue<T>;

@@ -30,2 +32,3 @@ receiver: MessageReceiver<T>;

deadLetters?: ActorRef;
budget: Required<Budget>;
}): Mailbox<T>;

@@ -32,0 +35,0 @@ private constructor();

@@ -15,6 +15,8 @@ import { Opened, Idle, Closed, setScheduled, setIdle, setClosed, setSuspended, isClosed, isOpened } from './mailbox-status.js';

#queue;
static create({ messageQueue, receiver, dispatcher, deadLetters, }) {
return new Mailbox(messageQueue, receiver, dispatcher, deadLetters);
budget;
static create({ messageQueue, receiver, dispatcher, deadLetters, budget, }) {
return new Mailbox(messageQueue, receiver, budget, dispatcher, deadLetters);
}
constructor(messageQueue, receiver, dispatcher, deadLetters) {
constructor(messageQueue, receiver, budget, dispatcher, deadLetters) {
this.budget = budget;
this.#queue = messageQueue;

@@ -88,3 +90,3 @@ this.#receiver = receiver;

this.#processAllSystemMessages();
this.#processMessages(Math.max(this.#dispatcher.budget.throughput, 1), startTime);
this.#processMessages(Math.max(this.budget.throughput, 1), startTime);
}

@@ -122,3 +124,3 @@ catch (error) {

return (this.#dispatcher.scheduler.shouldYield?.() ??
performance.now() - startTime >= this.#dispatcher.budget.deadline);
performance.now() - startTime >= this.budget.deadline);
}

@@ -125,0 +127,0 @@ }

{
"name": "@actor-system/core",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",

@@ -5,0 +5,0 @@ "scripts": {