@actor-system/spawn-protocol 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import { Behavior } from '@actor-system/core';
2
+ import { Command } from './command.js';
3
+
4
+ declare const behavior: <T>() => Behavior<Command<T>>;
5
+
6
+ export { behavior };
@@ -0,0 +1,6 @@
1
+ import { Behavior } from '@actor-system/core/internal';
2
+ import { Command } from './command.internal.js';
3
+
4
+ declare const behavior: <T>() => Behavior<Command<T>>;
5
+
6
+ export { behavior };
@@ -0,0 +1,13 @@
1
+ import { receive, same } from '@actor-system/behaviors';
2
+ import { isSpawn } from './command.js';
3
+
4
+ const behavior = () => receive((msg, context) => {
5
+ if (!isSpawn(msg))
6
+ return same;
7
+ const { behavior, name, replyTo } = msg;
8
+ const actorRef = context.spawn(behavior, name);
9
+ replyTo.tell(actorRef);
10
+ return same;
11
+ });
12
+
13
+ export { behavior };
@@ -0,0 +1,17 @@
1
+ import { ActorProps, Behavior, ActorRef } from '@actor-system/core';
2
+ import { Letter } from '@actor-system/mail';
3
+
4
+ type Command<T = unknown> = Spawn<T>;
5
+ interface Spawn<T> extends Letter<typeof $spawn> {
6
+ readonly name?: string;
7
+ readonly props?: ActorProps;
8
+ readonly behavior: Behavior<T>;
9
+ readonly replyTo: ActorRef<ActorRef<T>>;
10
+ }
11
+ declare const $spawn: "spawn";
12
+ declare const spawn: <T>({ name, props, replyTo, behavior, }: Letter.ExcludeLabel<Spawn<T>>) => Spawn<T>;
13
+ declare const isSpawn: <T>(value: unknown) => value is Spawn<T>;
14
+ declare const isCommand: <T>(value: unknown) => value is Command<T>;
15
+
16
+ export { $spawn, isCommand, isSpawn, spawn };
17
+ export type { Command, Spawn };
@@ -0,0 +1,17 @@
1
+ import { ActorProps, Behavior, ActorRef } from '@actor-system/core/internal';
2
+ import { Letter } from '@actor-system/mail/internal';
3
+
4
+ type Command<T = unknown> = Spawn<T>;
5
+ interface Spawn<T> extends Letter<typeof $spawn> {
6
+ readonly name?: string;
7
+ readonly props?: ActorProps;
8
+ readonly behavior: Behavior<T>;
9
+ readonly replyTo: ActorRef<ActorRef<T>>;
10
+ }
11
+ declare const $spawn: "spawn";
12
+ declare const spawn: <T>({ name, props, replyTo, behavior, }: Letter.ExcludeLabel<Spawn<T>>) => Spawn<T>;
13
+ declare const isSpawn: <T>(value: unknown) => value is Spawn<T>;
14
+ declare const isCommand: <T>(value: unknown) => value is Command<T>;
15
+
16
+ export { $spawn, isCommand, isSpawn, spawn };
17
+ export type { Command, Spawn };
@@ -0,0 +1,14 @@
1
+ import { letterGuard } from '@actor-system/mail';
2
+
3
+ const $spawn = "spawn";
4
+ const spawn = ({ name, props, replyTo, behavior, }) => ({
5
+ name,
6
+ props,
7
+ replyTo,
8
+ behavior,
9
+ label: $spawn,
10
+ });
11
+ const isSpawn = letterGuard($spawn);
12
+ const isCommand = letterGuard($spawn);
13
+
14
+ export { $spawn, isCommand, isSpawn, spawn };
@@ -0,0 +1,4 @@
1
+ export { behavior } from './behavior.js';
2
+ import * as command_d from './command.js';
3
+ export { command_d as cmd };
4
+ export { Command } from './command.js';
@@ -0,0 +1,4 @@
1
+ export { behavior } from './behavior.internal.js';
2
+ import * as command_d from './command.internal.js';
3
+ export { command_d as cmd };
4
+ export { Command } from './command.internal.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { behavior } from './behavior.js';
2
+ import * as command from './command.js';
3
+ export { command as cmd };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@actor-system/spawn-protocol",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "scripts": {
6
+ "type-check": "tsc -b src",
7
+ "lint": "eslint src",
8
+ "lint:fix": "eslint src --fix",
9
+ "publint": "publint",
10
+ "build:tsc:internal": "tsc -b src/tsconfig.lib.json",
11
+ "build:tsc:trimmed": "tsc -b src/tsconfig.lib.trimmed.json",
12
+ "build:rollup": "rollup -c node:config/rollup-config"
13
+ },
14
+ "module": "./dist/index.js",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./internal": {
26
+ "types": "./dist/index.internal.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "bundleDependencies": [
32
+ "@actor-system/shared"
33
+ ],
34
+ "dependencies": {
35
+ "@actor-system/behaviors": "0.0.1",
36
+ "@actor-system/core": "0.0.1",
37
+ "@actor-system/mail": "0.0.1"
38
+ },
39
+ "devDependencies": {
40
+ "@actor-system/testing": "0.0.1",
41
+ "@actor-system/shared": "0.0.1",
42
+ "config": "^1.0.0"
43
+ }
44
+ }